LeetCode刷题(24)
来源:互联网 发布:mac 用什么看图软件 编辑:程序博客网 时间:2024/06/10 09:50
Jump Game:
在可选的范围内,选择可以到达最远方的点作为新点,并开始新的搜寻,如果遇到0,且已经是最远可达,那么就无法到达终点。
class Solution(object): def canJump(self, nums): """ :type nums: List[int] :rtype: bool """ if len(nums) == 0: return False elif len(nums) == 1: return True step = 0 while step < len(nums): if nums[step] == 0: return False elif nums[step] + step >= len(nums) - 1: return True else : gmax = 0 for j in range(nums[step]): if nums[step+j+1]+step+j+1 > gmax: gmax = nums[step+j+1]+step+j+1 g = step+j+1 step = g
阅读全文
0 0
- LeetCode刷题(24)
- 【leetcode】leetcode 刷题 笔记 (不定期更新)
- leetcode刷题(Python)
- LeetCode刷题(1)
- LeetCode刷题(2)
- LeetCode刷题(3)
- LeetCode刷题(废弃)
- LeetCode刷题(FizzBuzz)
- Leetcode刷题(1)
- Leetcode刷题(2)
- Leetcode刷题(3)
- Leetcode刷题(4)
- Leetcode刷题(5)
- Leetcode刷题(6)
- Leetcode刷题(7)
- Leetcode刷题(13)
- Leetcode刷题(17)
- LeetCode刷题(18)
- Codeforces Round #436 (Div. 2) E. Fire (有放入顺序有关的01背包)
- 多线程-线程同步问题
- python笔记
- java8之lambda表达式
- 基于TextRank的关键词、短语、摘要提取
- LeetCode刷题(24)
- CSS基础笔记
- 国外十大高校人工智能实验室及其代表性人物一览
- 1--springBoot的注解使用,aspectj注解的使用,配置类的使用
- 新京报整版广告!360葫芦里卖的什么药?
- C++根据文件路径获取文件名
- Safari地址栏搜索没有反应的解决办法
- vue.js原生组件化开发——父子组件
- 2017.10.27 数学期望(手把手教你推期望) 解题报告