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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章