任务:
63. 股票的最大利润
1. 思路
- 暴力
- 时间复杂度太高
- 动态规划
2. 动态规划
class Solution:def maxProfit(self, prices: List[int]) -> int://初始化成本和利润//成本为正无穷//利润为0cost, profit = float("+inf"), 0//遍历for price in prices:// 成本要选择当前最小的cost = min(cost, price)// 利润选择现在的状态-成本和上一次的利润比较得到最大的profit = max(profit, price - cost)//返回利润return profit
