class Solution {
public:
bool hasGroupsSizeX(vector<int>& deck) {
map<int, int> hash_map;//number-count
for (auto x : deck)
hash_map[x]++;
int max = hash_map.begin()->second;//max为要找的最大公约数
for (auto i = hash_map.begin(); i != hash_map.end(); i++)
{
max = gcd(max, i->second);
}
return max >= 2;
}
int gcd(int x, int y) {//找x、y的最大公约数
return !x ? y : gcd(y % x, x);
}
};