122. 买卖股票的最佳时机 II
题目描述
代码实现
class Solution:
def maxProfit(self, prices: List[int]) -> int:
"""
只要股票当天较前一天在上涨,就可以做交易以获得最大利润
"""
profit = 0
for i in range(1, len(prices)):
if prices[i] > prices[i-1]:
profit += prices[i] - prices[i-1]
# profit += max(0, prices[i] - prices[i-1])
return profit