方法一:一次遍历
class Solution:
def maxProfit(self, prices: List[int]) -> int:
minprice = 10**9 # 记录历史最低价
maxprofit = 0 # 记录最大利润
for price in prices:
maxprofit = max(maxprofit, price - minprice)
minprice = min(minprice, price)
return maxprofit