Bootstrap

python-leetcode-买卖股票的最佳时机 II

122. 买卖股票的最佳时机 II - 力扣(LeetCode)

class Solution:
    def maxProfit(self, prices: List[int]) -> int:
        max_profit = 0  # 初始化最大利润为0
        for i in range(1, len(prices)):
            if prices[i] > prices[i - 1]:
                max_profit += prices[i] - prices[i - 1]  # 累加利润

        return max_profit

;