309. Best Time to Buy and Sell Stock with Cooldown
Last updated
Last updated
class Solution(object):
def maxProfit(self, prices):
"""
:type prices: List[int]
:rtype: int
"""
if len(prices) == 0: return 0
s0 = [0] * len(prices)
s1 = [0] * len(prices)
s2 = [0] * len(prices)
s0[0] = 0
s1[0] = -prices[0]
s2[0] = -sys.maxint
for i in range(1, len(prices)):
s0[i] = max(s0[i-1], s2[i-1])
s1[i] = max(s1[i-1], s0[i-1] - prices[i])
s2[i] = s1[i-1] + prices[i]
return max(s0[-1], s2[-1])