leetcode Jump Game II python
@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的更多相关文章
- [leetcode]Word Ladder II @ Python
[leetcode]Word Ladder II @ Python 原题地址:http://oj.leetcode.com/problems/word-ladder-ii/ 参考文献:http://b ...
- LeetCode: Jump Game II 解题报告
Jump Game II Given an array of non-negative integers, you are initially positioned at the first inde ...
- [LeetCode] Jump Game II 跳跃游戏之二
Given an array of non-negative integers, you are initially positioned at the first index of the arra ...
- LeetCode——Jump Game II
Description: Given an array of non-negative integers, you are initially positioned at the first inde ...
- [LeetCode] Jump Game II 贪心
Given an array of non-negative integers, you are initially positioned at the first index of the arra ...
- Leetcode jump Game II
Given an array of non-negative integers, you are initially positioned at the first index of the arra ...
- [LeetCode] Jump Game II(贪婪算法)
Given an array of non-negative integers, you are initially positioned at the first index of the arra ...
- leetcode–jump game II
1.题目描述 Given an array of non-negative integers, you are initially positioned at the first index of t ...
- [leetcode]Unique Paths II @ Python
原题地址:https://oj.leetcode.com/problems/unique-paths-ii/ 题意: Follow up for "Unique Paths": N ...
随机推荐
- 这辆车已覆盖免费wifi
上周在前面,首页特意下载了几部电影.即使步行到完成下载任务之前,,也推高了十分钟.所述无线网络和赶车之间,其实,我选择了前者. 真的很可怕大胆,要知道.其他人可能是买不来的旅行. 幸运的是,.速度依然 ...
- swift Dictionary 字典
// // main.swift // 字典 // // Created by zhangbiao on 14-6-15. // Copyright (c) 2014年 理想. All rig ...
- Javascript 中的false,零值,null,undefined和空字符串对象
在Javascript中,我们经常会接触到题目中提到的这5个比较特别的对象--false.0.空字符串.null和undefined.这几个对象很容易用错,因此在使用时必须得小心. 类型检测 我们下来 ...
- MySQL之终端(Terminal)管理数据库、数据表、数据的基本操作(转)
MySQL有很多的可视化管理工具,比如“mysql-workbench”和“sequel-pro-”. 现在我写MySQL的终端命令操作的文章,是想强化一下自己对于MySQL的理解,总会比使用图形化的 ...
- sqlserver数据库三范式的理解
从来都是听过概念,过一段时间就忘记了,根本就没有深入的理解.这次梳理一遍,用自己的方式记录一下. 1nf 原子性,不可拆分性 例如一张表里包含一个class属性(软件系,外语系,经贸系...)字段,这 ...
- SQL中DATEPART返回日期单独部分
定义和用法 DATEPART() 函数用于返回日期/时间的单独部分,比如年.月.日.小时.分钟等等. 语法 DATEPART(datepart,date) date 参数是合法的日期表达式.datep ...
- HTML4如何让一个DIV居中对齐?float输入日志标题
float:left,right clear:both 如何让一个DIV居中对齐? 第一步:设置外层的DIV的text-align:center; 第二步:设置里层的DIV的margin:auto 以 ...
- JS判断是否在微信浏览器打开
if (browser.versions.mobile) {//判断是否是移动设备打开.browser代码在下面 var ua = navigator.userAgent.toLowerCase(); ...
- 做了一个jquery插件,使表格的标题列可左右拉伸
示例下载 插件名称命名为:jquery.tableresize.js,代码如下: /* Writen by mlcactus, 2014-11-24 这是我封装的一个jquery插件,能够使table ...
- c语言 文件写入和读取
#include<stdio.h> #include<stdlib.h> #include<string.h> #define N 10 struct studen ...