Skip to content

Commit 709b710

Browse files
committed
Ruby Solution for Hand of Straights
1 parent 0c72347 commit 709b710

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

ruby/0846-hand-of-straights.rb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
def is_n_straight_hand(hand, w)
2+
hand = hand.sort()
3+
index = 0
4+
residual = []
5+
cur = []
6+
while(hand.length > 0)
7+
num = hand.shift
8+
if cur.size == 0
9+
cur << num
10+
else
11+
if num == cur[-1] + 1
12+
cur << num
13+
elsif num == cur[-1]
14+
residual << num
15+
elsif num > cur[-1] + 1
16+
return false
17+
end
18+
end
19+
if cur.length == w
20+
hand = residual + hand
21+
cur = []
22+
residual = []
23+
end
24+
25+
end
26+
return (cur.size == 0 or cur.size == w)
27+
28+
end

0 commit comments

Comments
 (0)