122. Best Time to Buy and Sell Stock II

来源:互联网 发布:js contains方法 编辑:程序博客网 时间:2024/06/11 08:01
class Solution(object):
    def maxProfit(self, prices):
        """
        :type prices: List[int]
        :rtype: int
        """
        res=0
        for i in range(1,len(prices)):
            if prices[i]-prices[i-1]>0:
                res+=prices[i]-prices[i-1]

        return res

距离一样,直接过去和跳着过去距离是一样的

原创粉丝点击