Skip to content

Commit 6832d7d

Browse files
Create Hands_of_Straights.py
1 parent cad6516 commit 6832d7d

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

Hands_of_Straights.py

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
class Solution(object):
2+
def find_successors(self, hand, groupSize, i, n):
3+
next_val = hand[i] + 1
4+
hand[i] = -1 # Mark as used
5+
count = 1
6+
i += 1
7+
while i < n and count < groupSize:
8+
if hand[i] == next_val:
9+
next_val = hand[i] + 1
10+
hand[i] = -1
11+
count += 1
12+
i += 1
13+
return count == groupSize
14+
15+
def isNStraightHand(self, hand, groupSize):
16+
n = len(hand)
17+
if n % groupSize != 0:
18+
return False
19+
hand.sort()
20+
for i in range(n):
21+
if hand[i] >= 0:
22+
if not self.find_successors(hand, groupSize, i, n):
23+
return False
24+
return True
25+

0 commit comments

Comments
 (0)