122.買賣股票的最佳時機II
class Solution:
def maxProfit(self, prices: List[int]) -> int:
result = 0
for i in range(len(prices)-1):
if prices[i+1] - prices[i] > 0:
result += prices[i+1] - prices[i]
return result
55. 跳躍遊戲
class Solution:
def canJump(self, nums: List[int]) -> bool:
if len(nums) == 1:
return True
cover = 0
i = 0
while i <= cover:
cover = max(nums[i]+i, cover)
if cover >= len(nums)-1:
return True
i += 1
return False
45.跳躍遊戲II