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. PHP foreach 引用 &

    以前用foreach,总喜欢在第二次遍历时改变value的拼写,比如 $x = array("a", "b", "c"); foreach ...

  2. 一篇关于for循环的简单题练习,

    package practice; public class Practice { public static void main(String[] args) { 7.      *     **  ...

  3. PHPStorm 远程开发教程

    目的:实现在windows下开发,而所改变代码自动同步到虚拟机 查看虚拟机的 IP地址 配置代码自动同步信息 通过页面上部的选项卡,切换到 Mappings 根路径:指的都是项目代码的根路径 点击一次 ...

  4. 处理webp加所有的jpg到指定路径

    #!/bin/shfunction getdir(){compareName='.webp';for element in `ls $1`dodir_or_file=$1"/"$e ...

  5. shiro细节、默认的过滤器、匹配模式和顺序

    部分细节 [urls] 部分的配置,其格式是:“url=拦截器[参数],拦截器[参数]”: 如果当前请求的url匹配[urls] 部分的某个url模式,将会执行其配置的拦截器. anon(anonym ...

  6. laravel5.8 表单验证

    'name' => 'required|unique:posts|max:255', // posts 表名 源码  vendor\laravel\framework\src\Illuminat ...

  7. VS编译器问题总结

    error C2236: 意外的“class”“CTsgBaseTask”.是否忘记了“;”? 出现这个问题的原因是在引用的一个头文件中定义的一个类最后没有加分号";".

  8. nslookup 工具的使用方法记录

    查询IP地址 nslookup最简单的用法就是查询域名对应的IP地址,包括A记录和CNAME记录,如果查到的是CNAME记录还会返回别名记录的设置情况.其用法是: nslookup 域名 定查询记录类 ...

  9. Mybatis的体系结构(转载)

    原文:http://blog.csdn.net/hupanfeng/article/details/9068003/ MyBatis的前身叫iBatis,本是apache的一个开源项目, 2010年这 ...

  10. .NET mocking框架Telerik JustMock发布R2 2019|附下载

    Telerik JustMock是一个灵活.功能齐全的.NET mocking框架.Telerik JustMock能够简化单元测试,现在测试复杂的场景比以前更加容易了.同时JustMock还与Vis ...