Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 8309641

Browse files
add 0055 go tanxin
1 parent f7d5b71 commit 8309641

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

‎problems/0055.跳跃游戏.md‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,31 @@ func canJUmp(nums []int) bool {
139139
}
140140
```
141141

142+
```go
143+
// 贪心
144+
func canJump(nums []int) bool {
145+
cover := 0
146+
n := len(nums)-1
147+
for i := 0; i <= cover; i++ { // 每次与覆盖值比较
148+
cover = max(i+nums[i], cover) //每走一步都将 cover 更新为最大值
149+
if cover >= n {
150+
return true
151+
}
152+
}
153+
return false
154+
}
155+
func max(a, b int ) int {
156+
if a > b {
157+
return a
158+
}
159+
return b
160+
}
161+
```
162+
163+
164+
142165
### Javascript
166+
143167
```Javascript
144168
var canJump = function(nums) {
145169
if(nums.length === 1) return true

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /