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

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 石嘴山市| 崇明县| 长宁县| 龙南县| 全椒县| 英吉沙县| 内江市| 从江县| 昌吉市| 五家渠市| 永丰县| 梁平县| 盘山县| 金川县| 社会| 沿河| 南涧| 景宁| 临泉县| 临夏县| 昌宁县| 子洲县| 隆子县| 内乡县| 泾源县| 丰顺县| 闵行区| 庐江县| 铅山县| 北辰区| 咸丰县| 梅州市| 临高县| 林周县| 武邑县| 梁平县| 丽江市| 黎城县| 五家渠市| 兖州市| 深州市|