Skip to content

Commit

Permalink
0045.跳跃游戏||.md Javascript
Browse files Browse the repository at this point in the history
  • Loading branch information
fusunx committed May 30, 2021
1 parent 1b39577 commit 60ad3b0
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions problems/0045.跳跃游戏II.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,26 @@ func jump(nums []int) int {
}
return dp[len(nums)-1]
}
```

Javascript:
```Javascript
var jump = function(nums) {
let curIndex = 0
let nextIndex = 0
let steps = 0
for(let i = 0; i < nums.length - 1; i++) {
nextIndex = Math.max(nums[i] + i, nextIndex)
if(i === curIndex) {
curIndex = nextIndex
steps++
}
}

return steps
};
```

/*
dp[i]表示从起点到当前位置的最小跳跃次数
dp[i]=min(dp[j]+1,dp[i]) 表示从j位置用一步跳跃到当前位置,这个j位置可能有很多个,却最小一个就可以
Expand Down

0 comments on commit 60ad3b0

Please sign in to comment.