【leetcode】】卡牌分组

//的确不用判断x与y的大小关系
int gcd(int x,int y){
    if(y==0) return x;
    return gcd(y,x%y);
}
bool hasGroupsSizeX(int* deck, int deckSize){
    if (deck == NULL || deckSize <2)
        return false;
    int i,j;
    int max = 10000;
    int* hash = (int*)calloc(max+1,sizeof(int));
    for (i=0; i<deckSize; i++)
        hash[deck[i]]++;
    int X=hash[0];
    for (j=0; j<=max; j++)
    {
        if(hash[j]==1) return false;
        //X记录数组deck中所有数字出现次数的gcd
        X=gcd(X,hash[j]);
        if(X==1) return false;
    }
    return true;    
}
原文地址:https://www.cnblogs.com/ganxiang/p/13561317.html