力扣第914题 卡牌分组

力扣第914题 卡牌分组

class Solution {
    public:
    int gcd(int a, int b)
    {
        return !a ? b : gcd(b % a, a);
    }

    bool hasGroupsSizeX(vector<int>& deck) 
    {
        int temp[10000] = {0};
        for (auto a : deck) temp[a]++;
        int g = 0;
        for (int i = 0; i < 10000; i++)
        {
            if (!temp[i])
                continue;
            g = gcd(g, temp[i]);
            if (g < 2)
                return false;
        }
        return g >= 2;
    }

};
原文地址:https://www.cnblogs.com/woodjay/p/12585123.html