leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

0846.cpp (605B)


      1 class Solution {
      2   public:
      3     bool isNStraightHand(const vector<int> &hand, const int groupSize) const {
      4         map<int, int> um;
      5         for (const int num : hand)
      6             um[num]++;
      7         for (auto start = begin(um); start != end(um); start++) {
      8             const auto [crnt, step] = *start;
      9             if (!step) continue;
     10             for (int goal = crnt; goal < crnt + groupSize; goal++) {
     11                 auto it = um.find(goal);
     12                 if (it == end(um) || it->second < step) return false;
     13                 it->second -= step;
     14             }
     15         }
     16         return true;
     17     }
     18 };