力扣 121. 买卖股票的最佳时机

动态规划

1
2
3
4
5
6
7
8
def maxProfit(prices):
p_len = len(prices)
if p_len <= 1: return 0
profit, in_ = 0, prices[0]
for i in range(1, p_len):
in_ = min(prices[i], in_)
profit = max(profit, prices[i] - in_)
return profit
  • Copyright: Copyright is owned by the author. For commercial reprints, please contact the author for authorization. For non-commercial reprints, please indicate the source.
  • Copyrights © 2022 eightyninth
  • Visitors: | Views:

请我喝杯咖啡吧~

支付宝
微信