Jump Game
解法:贪心+状态记录
class Solution {public boolean canJump(int[] nums) {int index=0;for(int i=0;i<nums.length-1;i++){if(index>=i && index<nums[i]+i)index=nums[i]+i;if(index>=nums.length-1)return true;}return index>=nums.length-1;}}
Jump Game II
解法:贪心+记忆+边界值处理
class Solution {public int jump(int[] nums) {int end=0,count=0,maxend=0;for(int i=0;i<nums.length-1;i++){maxend=Math.max(i+nums[i],maxend);if(i==end){count++;end=maxend;if(end>=nums.length-1)return count;}}return count;}}