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. JavaEE--JSP详解

    一.JSP JSP全名为Java Server Pages,中文名叫java服务器页面,其根本是一个简化的Servlet设计,它是由Sun Microsystems公司倡导.许多公司参与一起建立的一种 ...

  2. win10 powershell禁止运行脚本解决

    win10 现在默认策略为 Restricted 该策略情况下是禁止在终端下运行脚本文件的,所以我们想要通过powershell 来运行我们的脚本文件的话就需要我们更改其策略才行,如下命令可以帮助你 ...

  3. TCPcopy环境搭建

    参考文档:https://github.com/session-replay-tools/tcpcopy 辅助机器Assistant Server: 1.下载最新版本 git clone git:// ...

  4. scala学习笔记(1)

    scala ------------------------- java语言脚本化 1.安装scala-2.12.1.msi 2.进入到scala的命令行 3.Tab键会有补全的功能 1.scala程 ...

  5. join 与 countdownlatch 的区别 扩展 栅栏 CyclicBarrier

    我们先看一个 小例子 , 使用 join 与CountDownSlatch 都可以完成 当1,2线程 完全结束后 3 线程 start 对比我们就能够知道 CountDownSlatch 比 JOIN ...

  6. suse清除kthrotlds木马病毒

    一.服务器感染了kthrotlds挖矿病毒 [root@51yt bin]# cd /bin/ [root@51yt bin]# wget https://busybox.net/downloads/ ...

  7. return和exit以及C语言递归函数

    return 在主函数main()中,return整个函数退出,在子函数中return,只退出子函数. exit exit无论在函数什么位置退出整个函数 递归函数 #include <stdio ...

  8. Python---面向对象的三大特征

    # 面向对象的三大特征 - 继承 - 封装 - 多态 # 继承 - 子类可以使用父类定义的内容或者行为等 - 继承的实现 - 父类:基类,超类:被继承的类, Base Class, Super Cla ...

  9. SpringCloud学习系列-Eureka服务注册与发现(2)

    构建 microservicecloud-eureka-7001 eureka服务注册中心Module 1.新建microservicecloud-eureka-7001 2.pom <proj ...

  10. Trie树简介

    Trie树, 即字典树, 又称单词查找树或键树, 多叉树 基本性质 根节点不包含字符,除根节点外每一个节点都只包含一个字符 从根节点到某一节点,路径上经过的字符连接起来,为该节点对应的字符串 每个节点 ...