leetcode---jump-game---贪心
来源:互联网 发布:cf数据异常23 0 编辑:程序博客网 时间:2024/06/05 17:46
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.
class Solution {public: bool canJump(int A[], int n) { if(n == 0) return true; int step = A[0]; int cur = 0; while(step > 0) { int maxStep = step; int id = cur; for(int i=cur+1; i < n && i<=cur+step; i++) { if(maxStep < A[i]) { maxStep = A[i]; id = i; } } cur = id + maxStep; if(cur >= n-1) return true; step = A[cur]; } return cur >= n-1; }};
阅读全文
0 1
- Leetcode 贪心 Jump Game
- [leetcode][贪心] Jump Game
- leetcode---Jump Game---贪心
- leetcode---jump-game---贪心
- Leetcode 贪心 Jump Game II
- [leetcode][贪心] Jump Game II
- leetCode #55 Jump Game 贪心
- LeetCode Jump Game(贪心算法)
- LeetCode Jump Game II(贪心)
- [leetcode]55. Jump Game 贪心
- leetcode 55. Jump Game [贪心]
- Jump Game (能否到达终点,贪心) 【leetcode】
- [LeetCode]Jump Game II(贪心&&DP!!!!!)
- LeetCode 之 Jump Game(贪心算法)
- leetCode #45 Jump Game II 贪心
- leetcode -- Jump Game II -- 贪心,要看
- LeetCode-55-Jump Game(贪心)-Medium
- leetcode 55. Jump Game-贪心算法
- C++重载、隐藏、覆盖的区别
- 笔试题(Linux)
- stm32内部温度芯片的驱动及应用实现
- 洛谷 1197 [JSOI2008]星球大战 并查集
- AVL平衡二叉树图解
- leetcode---jump-game---贪心
- 二叉树非递归遍历之中序遍历
- 版本控制软件-git
- redis sentinel
- Windows系统编译制作SpiderMonkey最新版mozjs-31.2.0版本
- xampp里的apache与VMware有端口冲突
- 读书笔记_图解HTTP
- Android Selector
- Failed to locate the winutils binary in the hadoop binary path java.io.IOException: Could not locat