Skip to content

Commit f875985

Browse files
committed
Runtime: 304 ms (Top 61.38%) | Memory: 15.7 MB (Top 75.38%)
1 parent 0e7b2d2 commit f875985

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# Runtime: 304 ms (Top 61.38%) | Memory: 15.7 MB (Top 75.38%)
2+
13
#####################################################################################################################
24
# Problem: Hand of Straights
35
# Solution : Hash Table, Min Heap
@@ -9,24 +11,24 @@ class Solution:
911
def isNStraightHand(self, hand: List[int], groupSize: int) -> bool:
1012
if len(hand) % groupSize:
1113
return False
12-
14+
1315
freq = collections.defaultdict(int)
14-
16+
1517
for num in hand:
1618
freq[num] += 1
17-
19+
1820
min_heap = list(freq.keys())
1921
heapq.heapify(min_heap)
20-
22+
2123
while min_heap:
2224
smallest = min_heap[0]
2325
for num in range(smallest, smallest + groupSize):
2426
if num not in freq:
2527
return False
2628
freq[num] -= 1
27-
29+
2830
if freq[num] == 0:
2931
if num != min_heap[0]:
3032
return False
31-
heapq.heappop(min_heap)
32-
return True
33+
heapq.heappop(min_heap)
34+
return True

0 commit comments

Comments
 (0)