Loading

[Python手撕]买卖股票(交易不限次)

class Solution:
    def maxProfit(self, prices: List[int]) -> int:

        n = len(prices)
        count = 0
        for i in range(1,n):
            if prices[i]>prices[i-1]:
                count += prices[i]-prices[i-1]
        return count

posted @ 2024-09-25 09:51  Duancf  阅读(17)  评论(0)    收藏  举报