leetcode题解
那时的风儿
这个作者很懒,什么都没留下…
展开
-
leetcode Jump Game python答案
分析:只要元素的值为0的那一步才有可能无法到达顶端。但是,如果它前面的元素能够跳过这个0,则仍然可以到达顶端。 相关算法:贪心算法(作者也在学习中) 代码: class Solution: # @param {integer[]} nums # @return {boolean} def canJump(self, nums): if 0 no原创 2015-06-08 21:23:32 · 1036 阅读 · 0 评论 -
leetcode Jump Game II 题解
逆推,从后往前开始。 每一次,都是寻找能到达本元素,同时与本元素距离最远的元素的位置。但是以下程序超时,各位朋友看一下,如何优化以下。 class Solution: # @param {integer[]} nums # @return {integer} def jump(self, nums): step = 0 self原创 2015-06-08 21:57:52 · 553 阅读 · 0 评论