leetcode 309. Best Time to Buy and Sell Stock with Cooldown

来源:互联网 发布:pla算法 迭代次数 编辑:程序博客网 时间:2024/06/05 22:56
class Solution(object):    def maxProfit(self, prices):        """        :type prices: List[int]        :rtype: int        """        """        https://discuss.leetcode.com/topic/30421/share-my-thinking-process/18        """        if len(prices) < 2:            return 0        sell,buy,pre_sell,pre_buy = 0,-prices[0],0,0        for price in prices:            pre_buy = buy            buy = max(pre_sell-price,pre_buy)            pre_sell = sell            sell = max(pre_buy+price,pre_sell)        return sell
阅读全文
0 0
原创粉丝点击