主要是想到 C<A+B ,官方图解释的很好。奇葩题。贪心法
from typing import List
class Solution:
def maxProfit(self, prices: List[int]) -> int:
sum=0
for i in range(len(prices)-1):
if prices[i+1]>prices[i]:
sum+=prices[i+1]-prices[i]
return sum
网友评论