Jump Game
来源:互联网 发布:无线信道检测软件 编辑:程序博客网 时间:2024/06/05 15:19
Convert Sorted Array to Binary Search Tree
Difficulty:Medium
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]
, returntrue
.A =
[3,2,1,0,4]
, returnfalse
.
Code
C++
Runtime: 16 ms
class Solution {public: bool canJump(vector<int>& nums) { if (nums.size() == 0) return false; int step = nums[0]; for(int i = 1; i < nums.size(); i++) if (step > 0) { step--; step = max(step, nums[i]); } else return false; return true; }};
0 0
- Jump Game
- Jump Game
- Jump Game
- Jump Game
- Jump Game
- Jump Game
- Jump Game
- Jump Game
- Jump Game
- Jump Game
- Jump Game
- Jump Game
- Jump Game
- Jump Game
- Jump Game
- Jump Game
- Jump Game
- Jump Game
- CentOS7安装Python3
- pci驱动框架
- Linux-awk命令详解
- POJ 3304 Segments 判断直线与线段相交
- 菜鸟学Android笔记(三十一):Response实现验证码
- Jump Game
- display的设定block;inline;inline-block
- AsyncDisplayKit -- ( facebook/新浪微博 ) 优化UI性能
- 记录
- Linux常用命令
- KD树在knn算法中的应用
- poj 1469 COURSES 【匈牙利匹配】
- HDU 4570 简单的DP
- Floyd-Warshall算法---求解任意两节点的最短路径