Skip to content

Commit 91598ce

Browse files
committed
Ruby Solution for Jump Game II
1 parent 0c72347 commit 91598ce

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

ruby/0045-jump-game-ii.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
def jump(nums)
2+
3+
result = 0
4+
l = r = 0
5+
6+
while (r< nums.size()-1)
7+
farthest = 0
8+
(l..r).each do |i|
9+
farthest = [farthest,(i + nums[i])].max
10+
end
11+
l= r+1
12+
r = farthest
13+
result +=1
14+
end
15+
16+
return result
17+
end

0 commit comments

Comments
 (0)