Leetcode 121: 买卖股票

题目:
在这里插入图片描述
代码:

class Solution:
    def maxProfit(self, prices: List[int]) -> int:
        if not prices:
            return 0
        
        profit = 0
        buy_stock = prices[0]
        for i in range(len(prices)):
            if buy_stock > prices[i]:
                buy_stock = prices[i]
            profit = max(prices[i] - buy_stock, profit)

        return profit

如果觉得不错,就点赞关注留言~
谢谢各位捧场~

猜你喜欢

转载自blog.csdn.net/BSCHN123/article/details/113831559