Skip to content

Latest commit

 

History

History
 
 

jumpGameII

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

跳跃游戏 II

LeetCode地址

代码

抄答案,这个只跳到了倒数第二个就算可以了,是不是有问题。

class Solution {
    public int jump(int[] nums) {
        int end = 0, maxPositions = 0, steps = 0;
        for (int i = 0; i < nums.length - 1; i++) {
            maxPositions = Math.max(maxPositions, i + nums[i]);
            if (i == end) {
                end = maxPositions;
                steps++;
            }
        }
        return steps;
    }
}