class Solution:
def maxProfit(self, prices) -> int:
min_num = prices[0]
compare = 0
for i, item in enumerate(prices):
min_num = min(min_num, prices[i])
if prices[i] > min_num:
compare = max(compare, prices[i] - min_num)
return compare
leetcode——121.买卖股票的第一佳时机---动态规划
最新推荐文章于 2024-11-01 15:19:21 发布