国产探花免费观看_亚洲丰满少妇自慰呻吟_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;      }  };


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 藁城市| 西充县| 三台县| 休宁县| 都安| 马山县| 东乌珠穆沁旗| 定远县| 罗江县| 井研县| 普格县| 株洲县| 武胜县| 游戏| 博客| 桂东县| 双鸭山市| 阿鲁科尔沁旗| 株洲市| 蒙山县| 巩留县| 仲巴县| 九江县| 河西区| 绥化市| 阜阳市| 恩平市| 鄯善县| 台安县| 宝清县| 临汾市| 上饶县| 邵阳县| 民县| 晋城| 驻马店市| 蓬溪县| 潞西市| 保靖县| 师宗县| 关岭|