Skip to content

Commit a365410

Browse files
authored
Create 846. Hand of Straights (#496)
2 parents e1dfa0c + fb97d48 commit a365410

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

846. Hand of Straights

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)