leetcode 121.买卖股票的最佳时机

张开发
2026/4/9 21:53:20 15 分钟阅读

分享文章

leetcode 121.买卖股票的最佳时机
从前往后遍历class Solution: def maxProfit(self, prices: List[int]) - int: if (len(prices)1): return 0 max_profit 0 min_price float(inf) for i in range(len(prices)): if prices[i] min_price: min_price prices[i] if max_profit (prices[i]-min_price): max_profit prices[i]-min_price return max_profit

更多文章