@link http://www.cnblogs.com/zuoyuan/p/3781953.html
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. Your goal is to reach the last index in the minimum number of jumps. For example:
Given array A = [2,3,1,1,4] The minimum number of jumps to reach the last index is 2. (Jump 1 step from index 0 to 1, then 3 steps to the last index.) Subscribe to see which companies asked this question class Solution(object):
def jump(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
ret=0
last=0
curr=0
for i in range(len(nums)):
       #this is the amazing place : ( i > last ) keep the current step
if i > last:
last=curr
ret+=1
curr=max(curr,i+nums[i])
return ret

leetcode Jump Game II python的更多相关文章

  1. [leetcode]Word Ladder II @ Python

    [leetcode]Word Ladder II @ Python 原题地址:http://oj.leetcode.com/problems/word-ladder-ii/ 参考文献:http://b ...

  2. LeetCode: Jump Game II 解题报告

    Jump Game II Given an array of non-negative integers, you are initially positioned at the first inde ...

  3. [LeetCode] Jump Game II 跳跃游戏之二

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

  4. LeetCode——Jump Game II

    Description: Given an array of non-negative integers, you are initially positioned at the first inde ...

  5. [LeetCode] Jump Game II 贪心

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

  6. Leetcode jump Game II

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

  7. [LeetCode] Jump Game II(贪婪算法)

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

  8. leetcode–jump game II

    1.题目描述 Given an array of non-negative integers, you are initially positioned at the first index of t ...

  9. [leetcode]Unique Paths II @ Python

    原题地址:https://oj.leetcode.com/problems/unique-paths-ii/ 题意: Follow up for "Unique Paths": N ...

随机推荐

  1. IOS 开展 分别制定了iphone 和 ipad 好? 或开发一个 Universal好?

    最近因为工作的需要,.因为时间短的开发周期 开发的需要 积 至iphone 和 ipad 台 执行 优势的版本号 1.安装包,轻松管理,分布 2.您下载iphone,ipad 会自己主动下载 3.审核 ...

  2. swift锁屏播放,音乐进度更新,专辑,歌手名显示

    我自己用的音乐播放器是自带的AVPlayer 导入头文件#import <MediaPlayer/MediaPlayer.h> 远程控制事件接收与处理- (void)viewWillApp ...

  3. CSS3 布局

    1.1 列布局   CSS3中新出现的多列布局(multi-column)是传统HTML网页中块状布局模式的有力扩充.这种新语法能够让WEB开发人员轻松的让文本呈现多列显示.我们知道,当一行文字太长时 ...

  4. Oracle如何禁止并行

    PURPOSE -------   To explain how to disable Parallel Execution on Session/System level     SCOPE &am ...

  5. Foundation 框架

    1.框架是有许多类,函数,方法,文档按照一定的逻辑组织起来的集合 2. Foundation框架是所有框架的基础 3.术语cocoa指的是foundation框架和appication kit框架 4 ...

  6. VirtualBox安装linux增强工具报错

    错误提示: Building the OpenGL support module                         [FAILED] 解决办法 cd /media/VBOXADDITIO ...

  7. 转:一个跨WINDOWS LINUX平台的线程类

     来源:http://blog.csdn.net/dengxu11/article/details/7232681 继Windows下实现一个CThread封装类之后,这里我再实现一个跨WINDOWS ...

  8. Android06-Fragment碎片

    ¨Fragment简介 ¨Fragment生命周期 ¨动态加载碎片Fragment Manager的使用   1.Fragment表示Activity中的一种行为或者一部分用户界面. 可以将Fragm ...

  9. getHibernateTemplate().find()

    find(String queryString, Object[] values); 这个方法后者的参数必须是一个数组,而不能是一个List. List ul=getHibernateTemplate ...

  10. 一步一步实现AS3拖放组件

    外话: 我之前在天地会上发布过一个拖放组件,http://bbs.9ria.com/thread-117535-1-1.html 应该有人看过吧,那时候年纪轻轻,写了个东西,那时候基本能满足需求 但是 ...