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

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

LeetCode Jump Game

2019-11-10 20:50:15
字體:
來源:轉載
供稿:網友

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


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 晋城| 出国| 东丽区| 虎林市| 宜阳县| 鄯善县| 西畴县| 望都县| 洮南市| 汉中市| 平度市| 平武县| 普兰店市| 乌海市| 高雄市| 饶平县| 襄樊市| 定边县| 荆门市| 康马县| 称多县| 上林县| 阿拉善左旗| 大安市| 新蔡县| 汶川县| 赤壁市| 吉木乃县| 叶城县| 龙海市| 平昌县| 屏南县| 历史| 兴文县| 叶城县| 蒙山县| 远安县| 芒康县| 南木林县| 元阳县| 灵璧县|