-
-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy path0846-hand-of-straights.py
More file actions
37 lines (33 loc) · 830 Bytes
/
0846-hand-of-straights.py
File metadata and controls
37 lines (33 loc) · 830 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# time complexity: O(n*m + nlogn)
# space complexity: O(n)
from typing import Counter, List
class Solution:
def isNStraightHand(self, hand: List[int], groupSize: int) -> bool:
hand.sort()
handCounter = Counter(hand)
if len(hand) % groupSize:
return False
for num in hand:
if handCounter[num]:
for currNum in range(num, num+groupSize):
handCounter[currNum] -= 1
if handCounter[currNum] < 0:
return False
return True
'''
{
1: 0
2: 0
3: 0
4: 0
6: 1
7: 1
8: 1
}
'''
hand = [1, 2, 3, 6, 2, 3, 4, 7, 8]
groupSize = 3
print(Solution().isNStraightHand(hand, groupSize))
hand = [1, 2, 3, 4, 5]
groupSize = 4
print(Solution().isNStraightHand(hand, groupSize))