这题的标签写啥dp啊,真是给醉了,就是把前后差值为正的找出来,加起来就好了。代码如下;
class Solution(object):
def maxProfit(self, prices):
"""
:type prices: List[int]
:rtype: int
"""
if len(prices) <= 1:
return 0
list1 = [prices[i + 1] - prices[i] for i in range(len(prices) - 1) if prices[i + 1] - prices[i] > 0]
return sum(list1)
本文探讨如何使用动态规划算法解决股票投资中寻找最大收益的问题,通过实例演示了如何通过比较前后股价差值并求和来计算最大可能收益。
129

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



