Problem#122 Best Time to Buy and Sell Stock II

Problem

在这里插入图片描述

Solution

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

猜你喜欢

转载自blog.csdn.net/gaolijing_/article/details/104701615
今日推荐