classSolution:defmaxProfit(self, prices: List[int])->int:
ans =0
N =len(prices)for i inrange(1,N):if prices[i]> prices[i-1]:
ans +=(prices[i]- prices[i-1])return ans
1. 思路2. 代码class Solution: def maxProfit(self, prices: List[int]) -> int: ans = 0 N = len(prices) for i in range(1,N): if prices[i] > prices[i-1]: ans += (prices[i] - prices[i-1]) .