剑指 Offer 63. 股票的最大利润(动态规划)
作者:互联网
方法一:一次遍历
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
标签:动态,Offer,int,price,记录,maxprofit,63,prices,minprice 来源: https://blog.csdn.net/Mai_M/article/details/120623064