leetcode刷题日记——914,卡牌分组

 此题主要是找到公约数的代码;

 力扣

找到他们的公约数

class Solution {
public:
    bool hasGroupsSizeX(vector& deck) {
            unordered_maphashmap;
            for(auto &c:deck){hashmap[c]++;}
          //  int c=0;
            //auto p=hashmap.begin();c=p->second;
           
           //bool flag=false;
                for(int x=2;x<=deck.size();x++)
                {        bool flag=true;
                         for(auto &[_,k]:hashmap)
                            {
                                if(k%x!=0){flag=false;  break;}//找到公约数
                            }
                            if(flag){return true;}


                }
   return false;
    }
};

你可能感兴趣的:(c++,算法,开发语言)