Skip to content

Commit

Permalink
Ruby Solution for Hand of Straights
Browse files Browse the repository at this point in the history
  • Loading branch information
saip7795 committed Dec 31, 2022
1 parent 0c72347 commit 709b710
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions ruby/0846-hand-of-straights.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
def is_n_straight_hand(hand, w)
hand = hand.sort()
index = 0
residual = []
cur = []
while(hand.length > 0)
num = hand.shift
if cur.size == 0
cur << num
else
if num == cur[-1] + 1
cur << num
elsif num == cur[-1]
residual << num
elsif num > cur[-1] + 1
return false
end
end
if cur.length == w
hand = residual + hand
cur = []
residual = []
end

end
return (cur.size == 0 or cur.size == w)

end

0 comments on commit 709b710

Please sign in to comment.