首页 > 试题广场 >

代码题:股票最大值。

leetcode 121:
def maxProfit(prices):
    max_profit, min_price  = 0, float('inf')
    for price in prices:
        min_price = min(price, min_price)
        profit  = price - min_price
        max_profit = max(max_profit, profit)
   return max_profit
发表于 2019-07-04 16:22:43 回复(0)