zoukankan      html  css  js  c++  java
  • 55. Jump Game

    Given an array of non-negative integers, you are initially positioned at the first index of the array.

    Each element in the array represents your maximum jump length at that position.

    Determine if you are able to reach the last index.

    For example:
    A = [2,3,1,1,4], return true.

    A = [3,2,1,0,4], return false.

    每一位数字代表你能跳的最大步数,判断给定数组能否从头跳转到队尾

    1     public boolean canJump(int[] nums) {
    2         int maxDepth = 0;
    3         for (int i=0;i<nums.length;i++)
    4         {
    5             if(i> maxDepth) return false;
    6             maxDepth = Math.max(maxDepth,i+nums[i]);
    7         }
    8         return true;  
    9     }
  • 相关阅读:
    代码4
    readline,readlines,read函数
    代码3
    find函数
    字典的循环和if语句
    代码2
    代码1
    python除法
    字符串
    print函数
  • 原文地址:https://www.cnblogs.com/wzj4858/p/7675842.html
Copyright © 2011-2022 走看看