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

首頁 > 學(xué)院 > 開發(fā)設(shè)計(jì) > 正文

LeetCode Jump Game

2019-11-10 18:11:42
字體:
供稿:網(wǎng)友

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;      }  };


發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 宜黄县| 枞阳县| 北京市| 汾西县| 安多县| 昌江| 凉城县| 鄂温| 岳池县| 金堂县| 英山县| 和顺县| 张掖市| 曲周县| 平昌县| 南昌县| 津南区| 甘肃省| 惠来县| 贵州省| 恩施市| 泾川县| 延庆县| 永兴县| 富锦市| 霍邱县| 桂林市| 南岸区| 苍溪县| 佛冈县| 长沙市| 措美县| 黎平县| 恩施市| 滦平县| 博白县| 峨眉山市| 苗栗县| 安乡县| 卢龙县| 大安市|