55. Jump Game

public class Solution {
    public boolean canJump(int[] nums) {
        int maxDistance=0;
        for(int i=0;i<nums.length;i++)
            if(i<=maxDistance)
            {
                maxDistance=Math.max(maxDistance, i+nums[i]);
                if(maxDistance>=nums.length-1)
                    return true;
            }
        return false;
    }
}

 

posted @ 2017-09-26 01:49  Weiyu Wang  阅读(136)  评论(0编辑  收藏  举报