Loading

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

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

        max_profit = 0
        min_price = prices[0]
        n = len(prices)

        for i in range(n):
            min_price = min(min_price,prices[i])
            max_profit = max(max_profit,prices[i]-min_price)
        
        return max_profit
posted @ 2024-09-25 09:51  Duancf  阅读(26)  评论(0)    收藏  举报