增加新题目
This commit is contained in:
25
贪心算法/跳跃游戏/main.go
Normal file
25
贪心算法/跳跃游戏/main.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package main
|
||||
|
||||
func main() {
|
||||
|
||||
}
|
||||
|
||||
func canJump(nums []int) bool {
|
||||
maxstep := 0
|
||||
for i := 0; i < len(nums); i++ {
|
||||
if maxstep == 0 {
|
||||
maxstep = nums[i] + (i + 1)
|
||||
continue
|
||||
}
|
||||
if (i + 1) <= maxstep {
|
||||
tmp := nums[i] + (i + 1)
|
||||
if tmp > maxstep {
|
||||
maxstep = tmp
|
||||
}
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
Reference in New Issue
Block a user