class Solution:
def maxProfit(self, prices):
"""
:type prices: List[int]
:rtype: int
"""
profits = 0
for day in range(len(prices)-1):
pro = prices[day+1] - prices[day]
if pro > 0:
profits += pro
return profits
leetcode - 122 - 买卖股票的最佳时机 II
本文介绍了一种股票买卖策略,通过遍历价格列表并计算每日价格差来确定最佳买卖时机,实现利润最大化。该算法适用于股票交易的动态规划问题。

被折叠的 条评论
为什么被折叠?



