题目:
https://leetcode-cn.com/problems/jump-game/
public class _55_CanJump { // 贪心算法 public boolean canJump(int[] nums) { int len = nums.length; int rightMost = 0; for (int i = 0; i < len; i++) { if (i <= rightMost) { rightMost = Math.max(rightMost, i + nums[i]); if (rightMost >= len - 1) { return true; } } } return false; } public static void main(String[] args) { int[] t = {3, 2, 1, 0, 4}; new _55_CanJump().canJump(t); } }