一、45. 跳跃游戏 II
代码:
class Solution:
def jump(self, nums: List[int]) -> int:
start = step = 0
end = 1
n = len(nums)
while end < n:
max_num = 0
for i in range(start,end):
max_num = max(max_num, i+nums[i])
start,end,step = end,max_num + 1,step+1
return step
二、 53. 最大子数组和
代码:
class Solution:
def maxSubArray(self, nums: List[int]) -> int:
for i in range(1, len(nums)):
nums[i] += max(nums[i-1], 0)
return max(nums)