版权声明:孔庆鑫 https://blog.csdn.net/kongqingxin12/article/details/85754808
class Solution {
public:
bool hasGroupsSizeX(vector<int>& deck) {
map<int, int>count_num;
for (int i = 0; i < deck.size(); ++i) {
count_num[deck[i]]++;
}
//寻找最小值
int the_least_common_divisor = INT_MAX;
for (auto j = count_num.begin(); j != count_num.end(); ++j) {
auto tmp = *j;
the_least_common_divisor = min(the_least_common_divisor, tmp.second);
}
if (the_least_common_divisor == 1)
return false;
for (auto j = count_num.begin(); j != count_num.end(); ++j) {
auto tmp = *j;
the_least_common_divisor = measer(tmp.second, the_least_common_divisor);
if (tmp.second%the_least_common_divisor != 0||the_least_common_divisor==1)
return false;
}
return true;
}
int measer(int x, int y)
{
int z = y;
while (x%y!=0)
{
z = x % y;
x = y;
y = z;
}
return z;
}
};