当前位置:网站首页>Leetcode 55 jump game

Leetcode 55 jump game

2022-06-12 01:44:00 baj001

Ideas

Original link

  1. To jump to the last position , It's just calculation : Whether the jump coverage can cover the end point
  2. Use for Continuous cycle to update stay Current coverage Of New coverage
  3. If it appears Coverage ( That is, the maximum reachable index position ) Greater than or equal to Array of End index position when , explain : You can reach by jumping , return true
// Whether the jump coverage can cover the end point or not 
class Solution {
    
    public boolean canJump(int[] nums) {
    
        if(nums.length == 1){
    
            return true;
        }
        // The definition coverage is initially defined as 0
        int coverRange = 0;
        // Update the maximum coverage within the coverage , Coverage is actually the maximum reachable index location 
        for(int i = 0; i <= coverRange; i++){
    
            coverRange = Math.max(coverRange, i + nums[i]);
            if(coverRange >= nums.length - 1){
    
                return true;
            }
        }
        return false;
    }
}
原网站

版权声明
本文为[baj001]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/03/202203011216128222.html