力扣第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;
    }

};

posted on 2020-03-30 20:09  woodjay  阅读(76)  评论(0编辑  收藏  举报

导航