121. 买卖股票的最佳时机
class Solution:
def maxProfit(self, prices: List[int]) -> int:
minprice = prices[0]
maxprofit = 0
for i in prices:
minprice = min(minprice, i)
maxprofit = max(maxprofit, i - minprice)
return maxprofit
class Solution:
def maxProfit(self, prices: List[int]) -> int:
minprice = prices[0]
maxprofit = 0
for i in prices:
minprice = min(minprice, i)
maxprofit = max(maxprofit, i - minprice)
return maxprofit