55. Jump Game(贪心)
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.
Example 1:
Input: [2,3,1,1,4]
Output: true
Explanation: Jump 1 step from index 0 to 1, then 3 steps to the last index.
Example 2:
Input: [3,2,1,0,4]
Output: false
Explanation: You will always arrive at index 3 no matter what. Its maximum
jump length is 0, which makes it impossible to reach the last index. 贪心思想
如果当前存的步数now 小于于当前位置可以跳的步数,则更新now now 小于0则死掉了。
 class Solution {
     public boolean canJump(int[] nums) {
         int now = nums[0];
         for(int i =1;i<nums.length;i++){
             now--;
             if(now<0) return false;
             if(nums[i]>now){
             now = nums[i];
             }
         }
         return true;
     }
 }
55. Jump Game(贪心)的更多相关文章
- leetcode 55. Jump Game、45. Jump Game II(贪心)
		55. Jump Game 第一种方法: 只要找到一个方式可以到达,那当前位置就是可以到达的,所以可以break class Solution { public: bool canJump(vecto ... 
- 55. Jump Game   leetcode
		55. Jump Game Total Accepted: 95819 Total Submissions: 330538 Difficulty: Medium Given an array of n ... 
- [Leetcode][Python]55: Jump Game
		# -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 55: Jump Gamehttps://leetcode.com/probl ... 
- Leetcode 55. Jump Game & 45. Jump Game II
		55. Jump Game Description Given an array of non-negative integers, you are initially positioned at t ... 
- 刷题55. Jump Game
		一.题目说明 题目55. Jump Game,给定一组非负数,从第1个元素起,nums[i]表示你当前可以跳跃的最大值,计算能否到达最后一个index.难度是Medium. 二.我的解答 非常惭愧,这 ... 
- leetcode 55 Jump Game 三种方法,回溯、动态规划、贪心
		Given an array of non-negative integers, you are initially positioned at the first index of the arra ... 
- 55. Jump Game
		Given an array of non-negative integers, you are initially positioned at the first index of the arra ... 
- [LeetCode] 55. Jump Game 解题思路
		Given an array of non-negative integers, you are initially positioned at the first index of the arra ... 
- [LeetCode] 55. Jump Game 跳跃游戏
		Given an array of non-negative integers, you are initially positioned at the first index of the arra ... 
随机推荐
- 替换Quartus 自带编辑器 (转COM张)
			正文 此处以Quartus II 11.1和Notepad++ v5.9.6.2为例. 1. 使用QII自动调用Notepad++来打开HDL.sdc.txt等文件:并且可以在报错的时候,Notepa ... 
- 用ELK打造可视化集中式日志
			原文链接:https://yq.aliyun.com/articles/57420 摘要: Elk是Elastic search, Logstash和Kibana三者的简称. Elastic sear ... 
- [转]Android Activity的加载模式和onActivityResult方法之间的冲突
			前言 今天在调试程序时,发现在某一Activity上点击返回键会调用该Activity的onActivityResult()方法.我一开始用log,后来用断点跟踪调试半天,还是百思不得其解.因为之前其 ... 
- js---PC端滑动进度条
			这个是PC端的滑动进度条效果: <!doctype html> <html lang="en"> <head> <meta charset ... 
- Accelerated Failure Time Models加速失效时间模型AFT
			Weibull distribution 或者 σ是未知的scale参数,独立于X的常量, σ>0 是服从某一分布的随机变量 残差(residuals)= 
- DevOps之持续交付
			持续交付 持续交付是一种可以帮助团队以更短的周期交付软件的方法,该方法确保了团队可以在任何时间发布出可靠的软件.该方法意在以更快速度更高频率进行软件的构建.测试和发布. 通过对生产环境中的应用程序进行 ... 
- ABP之框架体系
			一 .框架体系的介绍 ABP框架采用的是DDD(领域驱动设计)的原则,可以很方便实现项目之间的松耦合,采用模块化的方式,方便对框架的扩展. 按照DDD的原则,首先将项目分为四层: 展现层:用来展现给用 ... 
- SPOJ BALNUM - Balanced Numbers - [数位DP][状态压缩]
			题目链接:http://www.spoj.com/problems/BALNUM/en/ Time limit: 0.123s Source limit: 50000B Memory limit: 1 ... 
- codeforces 869A/B/C
			A. The Artful Expedient time limit per test 1 second memory limit per test 256 megabytes input stand ... 
- AndroidStudio自定义TODO
			1.增加自定义TODO标记 Preferences -> Editor -> TODO,然后点击左下角的加号,输入想要自定义的TODO的正则 输入\bX\b.*(X为TODO标签的名字), ... 
