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

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

LeetCode 55. Jump Game

2019-11-08 02:20:02
字體:
來源:轉載
供稿:網友

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.

answer:

class Solution {public:    bool canJump(vector<int>& nums) {        int start = 0,end = 0;        while(end < nums.size()){            int max = 0;            for(end = start;end < nums.size(); end ++){                if(nums[end] == 0) break;            }            if(end >= nums.size() -1) return true;            for(int i = start; i < end; i ++){                int temp = nums[i] - (end - i);                if(temp > max) max = temp;            }            if(max <= 0){                return false;            }            nums[end] = max;            start = end;        }        return true;    }};


上一篇:poj 2676 Sudoku(dfs)

下一篇:HashMap 源碼解析

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 辰溪县| 阿克苏市| 辽阳县| 独山县| 屯门区| 太康县| 蒙阴县| 吉水县| 玛纳斯县| 土默特右旗| 中方县| 赤城县| 子洲县| 泸水县| 施甸县| 平原县| 荔浦县| 磐石市| 大安市| 青海省| 安远县| 鄂尔多斯市| 综艺| 保康县| 四子王旗| 天柱县| 宁化县| 中江县| 嘉黎县| 浦北县| 凤庆县| 禄劝| 新干县| 湖口县| 遂川县| 壶关县| 大新县| 唐海县| 九江县| 郁南县| 枣强县|