cpp
class Solution {
public:
int minimumRounds(vector<int>& tasks) {
int n=tasks.size(),sum=0;
sort(tasks.begin(),tasks.end()); //排序就不用哈希表
int a;
for(int i=0;i<n;){
int ct=0;
a=tasks[i];
while(i<n&&tasks[i]==a){
i++;ct++;
}
if(ct==1)return -1;
switch(ct%3){
case 0:sum+=ct/3;break;
case 1:sum+=ct/3+1;break;
case 2:sum+=ct/3+1;break;
}
}
return sum;
}
};