Skip to content

Commit ea2a0c1

Browse files
authored
Create 0055.Jump Game.swift
1 parent c43fecc commit ea2a0c1

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

0055.Jump Game.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution {
2+
func canJump(_ nums: [Int]) -> Bool {
3+
var minIndexThatLeadsToFinish = nums.count - 1
4+
5+
for i in stride(from: nums.count - 2, through: 0, by: -1) {
6+
if i + nums[i] >= minIndexThatLeadsToFinish {
7+
minIndexThatLeadsToFinish = i
8+
}
9+
}
10+
11+
return minIndexThatLeadsToFinish == 0
12+
}
13+
}

0 commit comments

Comments
 (0)