leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE |
0846.cpp (605B)
0 class Solution { 1 public: 2 bool isNStraightHand(const vector<int> &hand, const int groupSize) const { 3 map<int, int> um; 4 for (const int num : hand) 5 um[num]++; 6 for (auto start = begin(um); start != end(um); start++) { 7 const auto [crnt, step] = *start; 8 if (!step) continue; 9 for (int goal = crnt; goal < crnt + groupSize; goal++) { 10 auto it = um.find(goal); 11 if (it == end(um) || it->second < step) return false; 12 it->second -= step; 13 } 14 } 15 return true; 16 } 17 };