class Solution:
def maxProfit(self, prices):
"""
:type prices: List[int]
:rtype: int
"""
if len(prices) < 2:
return 0
minimum = prices[0]
profit = 0
for i in prices:
minimum = min(i, minimum)
profit = max(i-minimum,profit)
return profit
121. 买卖股票的最佳时机
最新推荐文章于 2023-11-01 15:23:08 发布