This commit is contained in:
2025-12-21 02:24:18 +08:00
parent 31ed535887
commit e0912887c2
3 changed files with 78 additions and 0 deletions

35
25/12/comp/20q1.cpp Normal file
View File

@@ -0,0 +1,35 @@
#include <unordered_map>
class Solution {
public:
int minOperations(std::vector<int>& nums) {
std::unordered_map<int, int> m;
int count = 0;
for(auto num: nums){
m[num] ++;
if (m[num] > 1) {
count++;
}
}
if(count == 0){
return 0;
}
int ans = 0;
for (int i = 0; i<nums.size(); i++) {
if (m[nums[i]] > 1) {
m[nums[i]]--;
count--;
}
if ((i + 1) % 3 == 0) {
ans++;
}
if (count == 0) {
if ((i + 1) % 3 != 0) {
ans++;
}
break;
}
}
return ans;
}
};