package com.zerroi.leetcode.ThreeSeven; import org.w3c.dom.css.CSSStyleDeclaration; public class CanJump { } /* * 给你一个非负整数数组 nums ,你最初位于数组的 第一个下标 。数组中的每个元素代表你在该位置可以跳跃的最大长度。 判断你是否能够到达最后一个下标,如果可以,返回 true ;否则,返回 false 。 * */ class SolutionFirst { public boolean canJump(int[] nums) { int step = 0; for (int i = 0; i < nums.length; i++) { // 当前位置可以跳跃的最大长度 step = Math.max(step, nums[i] + i); if (step >= nums.length - 1) return true; } return false; } }