2.买卖股票的最佳时机 II

版权声明:@author:geek_aaron https://blog.csdn.net/weixin_39433783/article/details/82984533

在这里插入图片描述
参考代码

class Solution:
    def maxProfit(self, prices):
        """
        :type prices: List[int]
        :rtype: int
        """
        if prices == None or len(prices) < 2:
            return 0
        profit = 0
        start_vaule=0
        for p in range(len(prices)-1):
            if prices[p] < prices[p+1]:
                start_vaule = prices[p+1]
                profit += prices[p+1]-prices[p]
                start_vaule = p
            else:
                start_vaule = min(start_vaule, p)
        return profit
slo = Solution()
print(slo.maxProfit([7,1,5,3,6,4]))


猜你喜欢

转载自blog.csdn.net/weixin_39433783/article/details/82984533