class Solution(object):
def maxProfit(self, prices):
"""
:type prices: List[int]
:rtype: int
"""
low_price, profit = float("+inf"), 0
for price in prices:
low_price = min(low_price, price)
profit = max(profit, price - low_price)
return profit
参考链接: