1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// @Title: 跳跃游戏 (Jump Game)
// @Author: 15816537946@163.com
// @Date: 2020-11-29 13:43:36
// @Runtime: 8 ms
// @Memory: 4 MB
// 贪心
func canJump(nums []int) bool {
	n, rightMost := len(nums)-1, 0
	for i := range nums {
		if i <= rightMost {
			rightMost = max(i+nums[i], rightMost)
		}
		if rightMost >= n {
			return true
		}
	}
	return false
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}