0%
解题思路
遍历一次数组即可
代码
1 2 3 4 5 6 7 8 9 10
| class Solution: def maxProfit(self, prices: List[int]) -> int: ret = 0 min_val = float('INF') for price in prices: min_val = min(min_val, price) profit = price - min_val if profit > ret: ret = profit return ret
|