55. 跳跃游戏
题目描述:
 给定一个非负整数数组 nums ,你最初位于数组的 第一个下标 。
数组中的每个元素代表你在该位置可以跳跃的最大长度。
判断你是否能够到达最后一个下标。
 
考察重点:由前至后遍历数组,maxPos记录我们当前可以到达的最远位置。
    public boolean canJump(int[] nums) {int maxPos = 0;for(int i = 0;i < nums.length;i ++){if(i > maxPos)		// 一旦出现不能到达i的情况,必然到达不了终点return false;maxPos = Math.max(maxPos, i + nums[i]);	// 可以到达当前结点i,则将可以到达的最远位置,与当前结点可以走的最远位置比较,并更新maxPosif(maxPos >= nums.length - 1)return true;}return true;}