1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| class Solution { public: bool isNStraightHand(vector<int>& hand, int groupSize) { sort(hand.begin(), hand.end()); unordered_map<int, int> mp; for (auto& h : hand) { mp[h]++; } for (int i = 0; i < hand.size(); i++) { if (mp[hand[i]] == 0) continue; for (int x = 0; x < groupSize; x++) { if (mp[hand[i] + x] == 0) { return false; } mp[hand[i] + x]--; } } return true; } };
|