这题的标签写啥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)