[Java][Leetcode middle] 55. 跳跃游戏
自己想的
每走一步都判断是否能够达到当前节点;如果能到达,更新最大步数。
public boolean canJump(int[] nums) {boolean result = true;int stepCount = nums[0];for (int i = 1; i < nums.length; i++) {// 还剩多少步可以走if(stepCount <=0 ){return false;}// 走到当前格子上:step-1stepCount--;// 更新为较大的步数if(stepCount < nums[i]) {stepCount = nums[i];}}return result;}