国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 合阳县| 上杭县| 德昌县| 交城县| 阿图什市| 登封市| 邻水| 宁阳县| 南开区| 民县| 汉寿县| 个旧市| 琼海市| 南漳县| 合江县| 江都市| 疏附县| 行唐县| 德昌县| 巍山| 孟津县| 临武县| 麦盖提县| 东兰县| 黑山县| 太康县| 大渡口区| 大城县| 仁怀市| 夹江县| 沂南县| 龙海市| 茌平县| 木里| 台山市| 日喀则市| 乌兰浩特市| 浪卡子县| 临西县| 黔南| 丽江市|