[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 ...
随机推荐
- 大纲2.3 Internet
Internet:域名系统基础知识和配置,上网查询访问的方法,常用电子邮件的种类和收发电子邮件的方法,网络信息搜索,网络信息下载.上传的基本方法,网络信息共享方法. DNS域名系统 域名 不区分大小写 ...
- Xamarin-Android_BaseAdapter 简单的复用
Xamarin-Android_BaseAdapter 简单的复用 缘由: 本人是一枚 小菜 初学Xamarin-Android 正在学习ListView 控件 发现这个控件的自定义布局 用的那叫一 ...
- BZOJ2612 : [Poi2003]Sums
设d[i]表示能拼出的x中满足x%a[0]=i的最小的x,其中d[0]=0. 若d[x%a[0]]<=x,则一定可以拼出x,否则一定不可以. 建出带权有向图,点的标号从0到a[0]-1,i号点向 ...
- BZOJ3459 : Bomb
二分答案,转化成判定所有科学家能否在lim时间内走到安全的地方 考虑网络流,对于每个非叶子节点,S向它连边,容量为该点科学家的人数 对于每个叶子节点,向T连边,容量为该点的容量 对于每个非叶子节点x, ...
- BZOJ 4636: 蒟蒻的数列 分块
4636: 蒟蒻的数列 题目连接: http://www.lydsy.com/JudgeOnline/problem.php?id=4636 Description 蒟蒻DCrusher不仅喜欢玩扑克 ...
- Cannot create a new pixel buffer adaptor with an asset writer input that has already started writing'
reason: '*** -[AVAssetWriterInputPixelBufferAdaptor initWithAssetWriterInput:sourcePixelBufferAttrib ...
- j.u.c系列(03)---之AQS:AQS简介
写在前面 Java的内置锁一直都是备受争议的,在JDK 1.6之前,synchronized这个重量级锁其性能一直都是较为低下,虽然在1.6后,进行大量的锁优化策略,但是与Lock相比synchron ...
- 面试必会函数源代码 strcpy/memcpy/atoi/kmp/quicksort
http://blog.csdn.net/liuqiyao_01/article/details/26967813 二.stl模板函数 1.strcpy char * strcpy( char *st ...
- 针对MyISAM锁表的解决方案
最近服务器上经常出现mysql进程占CPU100%的情况,使用show processlist命令后,看到出现了很多状态为LOCKED的sql.使用show status like 'table%'检 ...
- 群晖NAS简介(转)
Synology 群晖科技(Synology )创立于 2000 年,自始便专注于打造高效能.可靠.功能丰富且绿色环保的 NAS 服务器,是全球少数几家以单纯的提供网络存储解决方案获得世界认同的华人企 ...