[leetcode]Jump Game @ Python
原题地址:https://oj.leetcode.com/problems/jump-game/
题意:
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.
Determine if you are able to reach the last index.
For example:
A = [2,3,1,1,4]
, return true
.
A = [3,2,1,0,4]
, return false
.
代码:
class Solution:
# @param A, a list of integers
# @return a boolean
def canJump(self, A):
step = A[0]
for i in range(1, len(A)):
if step > 0:
step -= 1
step = max(step, A[i])
else:
return False
return True
[leetcode]Jump Game @ Python的更多相关文章
- leetcode Jump Game II python
@link http://www.cnblogs.com/zuoyuan/p/3781953.htmlGiven an array of non-negative integers, you are ...
- [LeetCode]题解(python):045-Jump game II
题目来源 https://leetcode.com/problems/jump-game-ii/ Given an array of non-negative integers, you are in ...
- [LeetCode]题解(python):055-Jump Game
题目来源 https://leetcode.com/problems/jump-game/ Given an array of non-negative integers, you are initi ...
- [LeetCode] Jump Game 跳跃游戏
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]题解(python):125 Valid Palindrome
题目来源 https://leetcode.com/problems/valid-palindrome/ Given a string, determine if it is a palindrome ...
- [LeetCode]题解(python):120 Triangle
题目来源 https://leetcode.com/problems/triangle/ Given a triangle, find the minimum path sum from top to ...
- [LeetCode]题解(python):119 Pascal's Triangle II
题目来源 https://leetcode.com/problems/pascals-triangle-ii/ Given an index k, return the kth row of the ...
- [LeetCode]题解(python):118 Pascal's Triangle
题目来源 https://leetcode.com/problems/pascals-triangle/ Given numRows, generate the first numRows of Pa ...
随机推荐
- RelativeLayout 高度宽度
RelativeLayout ss = (RelativeLayout) findViewById(R.id.myRelativeLayout); ss.setLayoutParams(new Rel ...
- 项目冲刺First
First Sprint 1.各个成员在 Alpha 阶段认领的任务(由于后面小组的讨论,修改本阶段的任务安排,()内为新任务安排) 蔡振翼:管理员界面.书籍管理,图书归还,消息,退出功能(撰写博客) ...
- hiho1270 建造基地([Offer收割]编程练习赛1)
题目意思很简单, 一道类似于背包的问题,问恰好超过背包容量的最小取值.并且需要计算n次,每计算一次都要将所有的物品的价值w[i] /= t,最后输出背包n次的总使用容量. 如果无法实现输出”No An ...
- CentOS以守护进程的方式启动程序的另类用法daemon
在Linux下如果以守护进程的方式启动程序,也就是后台运行,有几种方式,比如后面带&&,nuhop,那么在CentOS下可以使用daemon这个函数来启动,比如: daemon --p ...
- IDA .edata .rdata .idata .text segments
.rdata is for const data. It is the read only version of the .data segment. .idata holds the import ...
- User Agent Strings列表 — Kejun's Blog
曾经,ME 就需要这里的东西了. http://www.useragentstring.com/pages/All/
- Revit API修改链接文件房间边界
start [Transaction(TransactionMode.Manual)] [Regeneration(RegenerationOption.Manual)] );//设置房间边界 ...
- Revit API移动风管
移动风管曲线就可以移动风管 , , ));//向上移动3 ts.Commit(); return Result.Succeeded; } } url:http: ...
- vs2012\vs2013\vs2015碰到生成时报该错误:项目中不存在目标“GatherAllFilesToPublish”
手头一个vs2010升级到vs2012后,web项目发布到本地目录时项目报错:“该项目中不存在目标“GatherAllFilesToPublish”” 通过谷歌大神的帮助,找到了解决方法.共享之. 原 ...
- 完美.PCK文件不完全详解
building.pck:建筑物 configs.pck:配置文件interface.pck:玩过魔兽的都晓得这个是什么~interface顾名思义·facedata.pck,人物脸型,细节.不要改, ...