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


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 巢湖市| 永靖县| 云浮市| 彩票| 光山县| 正蓝旗| 瑞金市| 内丘县| 弋阳县| 岳普湖县| 南溪县| 长子县| 濉溪县| 长沙市| 渭源县| 灵台县| 巩留县| 临夏市| 汨罗市| 屏边| 陇川县| 宁夏| 嘉鱼县| 德令哈市| 佳木斯市| 南和县| 方正县| 红安县| 田阳县| 南投县| 吐鲁番市| 东平县| 科尔| 揭西县| 乌什县| 洱源县| 安徽省| 芒康县| 嘉黎县| 咸阳市| 泊头市|