This commit is contained in:
2025-12-21 21:18:47 +08:00
parent e0912887c2
commit f14466081c
3 changed files with 52 additions and 0 deletions

22
25/12/comp/21q3.cpp Normal file
View File

@@ -0,0 +1,22 @@
#include <unordered_map>
#include <vector>
class Solution {
public:
int minSwaps(std::vector<int>& nums, std::vector<int>& forbidden) {
std::unordered_map<int, int> m1,m2;
int n = nums.size();
for (int i = 0; i < n; i++)
{
m1[nums[i]]++;
m2[nums[i]]++;
}
for(auto [k,v] : m1){
if (v + m2[k] > n)
{
return -1;
}
}
// ❎未完成
}
};