Skip to content

Commit 18c3723

Browse files
authored
Create 846-Hand-of-Straights.py
1 parent 81c30c1 commit 18c3723

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

846-Hand-of-Straights.py

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class Solution:
2+
def isNStraightHand(self, hand: List[int], groupSize: int) -> bool:
3+
if len(hand) % groupSize:
4+
return False
5+
6+
count = {}
7+
for n in hand:
8+
count[n] = 1 + count.get(n, 0)
9+
10+
minH = list(count.keys())
11+
heapq.heapify(minH)
12+
while minH:
13+
first = minH[0]
14+
for i in range(first, first + groupSize):
15+
if i not in count:
16+
return False
17+
count[i] -= 1
18+
if count[i] == 0:
19+
if i != minH[0]:
20+
return False
21+
heapq.heappop(minH)
22+
return True

0 commit comments

Comments
 (0)