class Solution:
def maxProfit(self, prices: List[int]) -> int:
if not prices:
return 0
pre_min=[prices[0]]
for i in range(1,len(prices)):
pre_min.append(min(prices[:i]))
profit=[0]
for i in range(1,len(prices)):
profit.append(prices[i]-pre_min[i])
return max(profit)
网友评论