DP，we can create two array, buy and sell. buy[i] means we buy a stock at day i , and sell[i] means we sell a stock at day i.

so, we have two equations :

- buy[i] = max(buy[i-1] , sell[i-2] - prices[i]) // So we should use sell[i-2] means we cooldown one day.
- sell[i] = max(sell[i-1],buy[i-1] + prices[i])

finally, return the max(buy[n-1] , sell[n-1]) （it is obvious that sell[n-1] >= buy[n-1] ,so we return sell[n-1]）

if you want to see more about it, you can visit my blog : Best Time to Buy and Sell Stock with Cooldown

```
class Solution(object):
def maxProfit(self, prices):
"""
:type prices: List[int]
:rtype: int
"""
if not prices or len(prices) < 2: return 0
n = len(prices)
buy, sell = [0] * n, [0] * n
buy[0] = -prices[0]
buy[1] = max(-prices[0], -prices[1])
sell[1] = max(0, prices[1] - prices[0])
for i in xrange(2, n):
buy[i] = max(sell[i - 2] - prices[i], buy[i - 1])
sell[i] = max(buy[i - 1] + prices[i], sell[i - 1])
return sell[n - 1]
```