国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

LeetCode Jump Game

2019-11-10 18:31:49
字體:
來源:轉載
供稿:網友

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.

代碼如下:

class Solution {public:    bool canJump(vector<int>& nums)          {              if(nums.size() < 2)                  return true;                            int pos=0,currentMax=0,nextMax=0;              while(currentMax-pos+1 >0)            {                for(;pos<=currentMax;pos++)                {                    if(pos+nums[pos] > nextMax)                        nextMax = pos+nums[pos];                    if(nextMax >= nums.size()-1)                        return true;                }                currentMax = nextMax;            }            return false;      }  };


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 苍溪县| 花莲市| 肥乡县| 云阳县| 武安市| 南平市| 和林格尔县| 武山县| 五华县| 郑州市| 吴川市| 台南县| 锡林浩特市| 泽州县| 肃南| 土默特右旗| 四会市| 麻城市| 德格县| 灵宝市| 建平县| 宁晋县| 沅江市| 临漳县| 颍上县| 榆林市| 林西县| 永昌县| 贞丰县| 台湾省| 同德县| 集安市| 原平市| 南宁市| 德庆县| 崇文区| 建昌县| 浦江县| 沙坪坝区| 南京市| 吴江市|