914. 卡牌分组
思路:统计个数,然后求最小公约数
class Solution {
public:
bool hasGroupsSizeX(vector<int>& deck) {
int hash[10005];//统计个数
fill(hash, hash+10005, 0);
int len=deck.size();
int g;
for(int i=0;i<len;i++){
hash[deck[i]]++;
if(i==len-1)
g = hash[deck[i]];
}
for(int i=0;i<10005;i++){
if(hash[i]!=0){
g = gcd(g, hash[i]);//求公约数
}
}
return g!=1;
}
};