Skip to content

Commit caa3bd5

Browse files
committed
The LeetCode problem [55]'s Swift solution.
1 parent 21b260c commit caa3bd5

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

swift/55.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// 55. Jump Game
2+
3+
class Solution {
4+
func canJump(_ nums: [Int]) -> Bool {
5+
if nums.count == 0 {
6+
return true
7+
}
8+
9+
var max: Int = 0
10+
for i in 0..<nums.count {
11+
if i <= max {
12+
max = (i + nums[i]) > max ? (i + nums[i]) : max
13+
} else {
14+
break
15+
}
16+
}
17+
return max >= (nums.count - 1)
18+
}
19+
}

0 commit comments

Comments
 (0)