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

LeetCode122. 买卖股票的最佳时机 II

题目链接

https://leetcode.cn/problems/best-time-to-buy-and-sell-stock-ii/
在这里插入图片描述

代码

class Solution:
    def maxProfit(self, prices: List[int]) -> int:
        result = 0
        for i in range(1, len(prices)):
            result += max((prices[i] - prices[i - 1]), 0)
        return result

猜你喜欢

转载自blog.csdn.net/qq_44953660/article/details/132817220