python
class Solution:
def maxProfit(self, prices):
"""
:type prices: List[int]
:rtype: int
"""
if len(prices) < 2:
return 0
profit = 0
mininum = prices[0]
for i in prices:
mininum = min(i,mininum)
profit = max(i-mininum,profit)
return profit
思路:
同时保留最小值和最大差值