Skip to content

Commit

Permalink
Restructured version for Jump Game.
Browse files Browse the repository at this point in the history
  • Loading branch information
iHackSubhodip committed Nov 19, 2018
1 parent 1163c3d commit 37a340a
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions DP/JumpGame.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,19 @@

class JumpGame {
func canJump(_ nums: [Int]) -> Bool {
var max = 0
var maximumIndex = nums[0]

for i in 0 ..< nums.count {
let farestStep = i + nums[i]
if i > max {
for (currentIndex, value) in nums.enumerated(){

if currentIndex > maximumIndex{
return false
}
max = max > farestStep ? max : farestStep

maximumIndex = max(maximumIndex, currentIndex + value)
}

return true
}
}


0 comments on commit 37a340a

Please sign in to comment.