45. Jump Game II
来源:互联网 发布:python 字符转数字 编辑:程序博客网 时间:2024/06/07 06:54
class Solution(object):
def jump(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
n, start, end, step = len(nums), 0, 0, 0
while end < n - 1:
step += 1
maxend = end + 1
for i in range(start, end + 1):
if i + nums[i] >= n - 1:
return step
maxend = max(maxend, i + nums[i])
start, end = end + 1, maxend
def jump(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
n, start, end, step = len(nums), 0, 0, 0
while end < n - 1:
step += 1
maxend = end + 1
for i in range(start, end + 1):
if i + nums[i] >= n - 1:
return step
maxend = max(maxend, i + nums[i])
start, end = end + 1, maxend
return step
https://discuss.leetcode.com/topic/18815/10-lines-c-16ms-python-bfs-solutions-with-explanations
阅读全文
0 0
- 45. Jump Game II
- 45. Jump Game II
- 45. Jump Game II
- 45. Jump Game II
- 45. Jump Game II
- 45. Jump Game II
- 45. Jump Game II
- 45. Jump Game II
- 45. Jump Game II
- 45. Jump Game II
- 45. Jump Game II
- 45. Jump Game II
- 45. Jump Game II
- 45. Jump Game II
- 45. Jump Game II
- 45. Jump Game II
- 45. Jump Game II
- 45. Jump Game II
- 如何优化数据库
- 6.Flume Channel Selectors
- Applied Architecture Decoupling Handlers 实用做法:解耦处理函数
- Cookie Session
- JVM学习07:直接内存
- 45. Jump Game II
- RF射频卡的介绍与与手机NFC的通信
- protocol=http/1.1, code=400, message=Bad Request, url=*********
- 【C语言】getchar函数 以及ASCII码排序问题
- GIS三维解决方案
- 惩罚函数法(内点法、外点法)求解约束优化问题最优值 matlab
- java集合框架——LinkedList和源码分析
- MyBatis JdbcType 与Oracle、MySql数据类型对应关系详解
- 强化学习