122 买卖股票的最佳时机 II
class Solution:
def maxProfit(self, prices: List[int]) -> int:
l=len(prices)
ret=0
for i in range(1,l):
ret+=max(0,prices[i]-prices[i-1])
return ret
55 跳跃游戏
class Solution:
def canJump(self, nums: List[int]) -> bool:
l=len(nums)
r=0
for i in range(l):
if i<=r:
r=max(r,i+nums[i])
if r>=l-1:
return True
return False
45 跳跃游戏 II
class Solution:
def jump(self, nums: List[int]) -> int:
l=len(nums)
mostright=0
ret=0
end=0
for i in range(l-1):
mostright=max(mostright,i+nums[i])
if i==end:
end=mostright
ret+=1
return ret