We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent e1dfa0c commit fb97d48Copy full SHA for fb97d48
846. Hand of Straights
@@ -0,0 +1,26 @@
1
+class Solution {
2
+public:
3
+ bool isNStraightHand(vector<int>& nums, int k)
4
+ {
5
+ if(nums.size() % k) return false;
6
+
7
+ map<int,int>mp;
8
+ for(auto val:nums) mp[val]++;
9
10
+ int n = nums.size();
11
+ while(n--)
12
13
+ for(auto [a, b]:mp)
14
15
+ for(int i=a;i<a+k;i++)
16
17
+ if(mp[i] == 0) return false;
18
+ mp[i]--;
19
+ if(mp[i]==0) mp.erase(i);
20
+ }
21
+ break;
22
23
24
+ return true;
25
26
+};
0 commit comments