0055.跳跃游戏

方法一:贪心

时间复杂度 $O(n)$,空间复杂度 $O(1)$。

func canJump(nums []int) bool {
	maxStep, end := 0, 0
	for i := 0; i < len(nums)-1; i++ {
		if i+nums[i] > maxStep {
			maxStep = i + nums[i]
		}
		if end == i && maxStep > end {
			end = maxStep
		} else if end == i && maxStep <= end {
			return false
		}
	}
	return true
}