@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. 一个loader加载多个swf

    var _swfLoader:Loader; var _swfRequest:URLRequest; var _swfPathArr:Array = new Array("00.swf&qu ...

  2. Java反射及依赖注入简单模拟

    一.编写Dao类 ? 1 2 3 4 5 6 7 8 9 10 11 package cn.com.songjy.annotation;   import java.util.Date;   publ ...

  3. UVA - 10574 Counting Rectangles

    Description Problem H Counting Rectangles Input: Standard Input Output:Standard Output Time Limit: 3 ...

  4. 随机抽样一致性算法(RANSAC)

    本文翻译自维基百科,英文原文地址是:http://en.wikipedia.org/wiki/ransac,如果您英语不错,建议您直接查看原文. RANSAC是"RANdom SAmple ...

  5. MVC+simpleinjector 简单使用

    一.首先添加NuGet包如下图

  6. 使用 Oracle Sql plus的一点经验

    1    当你输入的语句有错误的时候,不用重新输入语句,直接输入ed就会出现一个文本文档显示之前输入的语句,这样你可以在文本文档里面修改语句,最后点保存. 2 三个set:设置每行显示的记录长度:SE ...

  7. js中添加事件 attachEvent 与 addEventListener

    给元素添加事件时,使用js进行实现时产生了疑惑,有关事件浏览器兼容的问题,在此记录如下. <!DOCTYPE html> <html> <head> <met ...

  8. zoj1093 Monkey and Banana

    写到现在,发现1025,1076之前写的都是同一种题型:关于DAG的最长路(最短路). 首先要建立模型,根据关系,确定点和点之间的关系,构成一个DAG,前面几道题每个点之间距离默认为1,这一道题不同点 ...

  9. C++中的namespace

    本文转载来自:http://blog.csdn.net/yao_zhuang/article/details/1853625 namespace中文意思是命名空间或者叫名字空间,传统的C++只有一个全 ...

  10. 矩阵乘法的MPI并行计算

    1.问题描述 矩阵乘法问题描述如下: 给定矩阵A和B,其中A是m*p大小矩阵,B是p*n大小的矩阵.求C = A*B. 求解这个问题最简单的算法是遍历A的行和B的列,求得C的相应元素,时间复杂度O(m ...