-
Notifications
You must be signed in to change notification settings - Fork 0
LC 0846 [M] Hand of Straights
Code with Senpai edited this page Jun 17, 2022
·
1 revision
class Solution:
def isNStraightHand(self, hand: List[int], groupSize: int) -> bool:
if len(hand) % groupSize:
return False
count = defaultdict(int)
for n in hand:
count[n] += 1
minH = list(count.keys())
heapify(minH)
while minH:
first = minH[0] # first in group
for i in range(first, first + groupSize):
if i not in count:
return False
count[i] -= 1
if count[i] == 0: # 2
if i != minH[0]: # [1,2,3],[(1),_,3]
return False
heappop(minH)
return True
footer