Skip to content

Commit

Permalink
Create: 55-Jump-Game.swift
Browse files Browse the repository at this point in the history
  • Loading branch information
Ykhan799 authored Aug 31, 2022
1 parent 56cf8ba commit 1dae25a
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions swift/55-Jump-Game.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class Solution {
func canJump(_ nums: [Int]) -> Bool {
var goal = nums.count - 1

for i in stride(from: nums.count-2, through: 0, by: -1){
if i + nums[i] >= goal {
goal = i
}
}
return goal == 0
}
}

0 comments on commit 1dae25a

Please sign in to comment.