Jump Game & Jump Game II

Jump Game   

解法:贪心+状态记录

class Solution {
    public boolean canJump(int[] nums) {
        int index=0;
        for(int i=0;i=i && index=nums.length-1)
                return true;
        }
        return index>=nums.length-1;
    }
}

Jump Game II

解法:贪心+记忆+边界值处理

class Solution {
    public int jump(int[] nums) {
        int end=0,count=0,maxend=0;
        for(int i=0;i=nums.length-1)
                    return count;
            }
        }
        return count;
    }
}

 

你可能感兴趣的:(Jump Game & Jump Game II)