mycode  71.47%

思路:

既然要到达终点,那么俺就可以倒推,要想到达n,可以有以下情况

1)到达n-1,然后该位置最少可以走一步

2)到达n-2,然后该位置最少可以走两步

3)到达n-3,然后该位置最少可以走三步

。。。。

emmmm...本来想按照这个方法写个函数,发现跑不通。。。。我就干脆先把list倒过来,当下个数大于等于,他能到达上一个数,但是当这个数暂时不能到达时,我就需要给下一个数加一个step的要求啦

class Solution(object):
def canJump(self, nums):
"""
:type nums: List[int]
:rtype: bool
"""
nums[:] = nums[::-1]
length = len(nums)
step = 1
for i in range(1,length):
if nums[i] >= step:
step = 1
continue
else:
step += 1
return step == 1

参考:

跟我的差不多,区别:我的目标--不断衡量距离,他的目标--不断改变目的地

class Solution(object):
def canJump(self, nums):
"""
:type nums: List[int]
:rtype: bool
"""
if not nums or len(nums)==1 : return True
des = len(nums) - 1
for i in range(len(nums)-2,-1,-1):
if nums[i] >= des - i:
des = i
return des == 0

leetcode-mid-dynamic programming-55. Jump Game的更多相关文章

  1. [LeetCode] 55. Jump Game_ Medium tag: Dynamic Programming

    Given an array of non-negative integers, you are initially positioned at the first index of the arra ...

  2. [LeetCode] 45. Jump Game II_ Hard tag: Dynamic Programming

    Given an array of non-negative integers, you are initially positioned at the first index of the arra ...

  3. [LeetCode] questions conclusion_ Dynamic Programming

    Questions: [LeetCode] 198. House Robber _Easy tag: Dynamic Programming [LeetCode] 221. Maximal Squar ...

  4. [LeetCode] 55. Jump Game 跳跃游戏

    Given an array of non-negative integers, you are initially positioned at the first index of the arra ...

  5. LeetCode 55. Jump Game (跳跃游戏)

    Given an array of non-negative integers, you are initially positioned at the first index of the arra ...

  6. 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 ...

  7. [Leetcode][Python]55: Jump Game

    # -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 55: Jump Gamehttps://leetcode.com/probl ...

  8. [LeetCode] 139. Word Break_ Medium tag: Dynamic Programming

    Given a non-empty string s and a dictionary wordDict containing a list of non-empty words, determine ...

  9. [LeetCode] 63. Unique Paths II_ Medium tag: Dynamic Programming

    A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). The ...

  10. [LeetCode] 121. Best Time to Buy and Sell Stock_Easy tag: Dynamic Programming

    Say you have an array for which the ith element is the price of a given stock on day i. If you were ...

随机推荐

  1. IDEA一些有用的功能

    使用 Type Info 如果你想要更多的关于符号的信息,例如从哪里或它的类型是什么, 快速文档可以很好的帮到您,您可以按下 Ctrl+Q 来调用它,然后你会看到一个包含这些细节的弹出窗口.如果您不需 ...

  2. sql认识

    DDL – Data Definition Language数据定义语言DML – Data Manipulation Language数据操作语言DCL – Data Control Languag ...

  3. 使用vue脚手架的项目如何引入JQuery第三方插件

    1:下载jquery npm install jquery --save 2:打开build文件夹下的webpack.base.conf.js文件: 1)在最上方 引入webpack  var web ...

  4. 右则css 小浮条

    <!--右边浮动--> <div class="indexfu"> <div class="indexfu2" id=" ...

  5. web页面请求历程

    web页面请求历程 1)准备DHCP,UDP,IP和以太网 客户端要访问www.google.com的网站. 首先客户端要与网络相接,没有IP地址地址就不能做什么事情,所以客户端采取的一个网络相关的动 ...

  6. 006-Zabbix agent on Zabbix server is unreachable for 5 minutes

    环境描述:        环境介绍:CentOS6.5   zabbix3.2.6(zabbix客户端与服务端在一台主机)   1.在安装完zabbix之后,添加客户端,客户端配置(zabbix_ag ...

  7. 2019牛客暑期多校训练营(第一场) A Equivalent Prefixes ( st 表 + 二分+分治)

    链接:https://ac.nowcoder.com/acm/contest/881/A 来源:牛客网 Equivalent Prefixes 时间限制:C/C++ 2秒,其他语言4秒 空间限制:C/ ...

  8. CentOS7 配置阿里云yum源,非常之简单

    1.进入yum的文件夹 命令:cd   /etc/yum.repos.d/ 2.下载wget 命令:yum -y install wget 命令:yum install bash-completion ...

  9. C# WinFrom自适应

    1.在窗体的Project中建一个自适应的类. 2.类的代码如下 public class AutoSizeForm { //(1).声明结构,只记录窗体和其控件的初始位置和大小. public st ...

  10. .align 5 .MACRO .ENDM .word

    ARM的.align 5就是2的5次方对齐,也就是4字节对齐 .macro <name> {<arg_1} {,<arg_2>} … {,<arg_N>} 定 ...