class Solution(object):
def maxProfit(self, prices):
"""
:type prices: List[int]
:rtype: int
"""
if not prices:
return 0
buy = [0 for i in range(len(prices))]
sell = [0 for i in range(len(prices))]
buy[0] = -prices[0]
for i in range(1,len(prices)):
# 状态好难定义
# 考虑第i天买股票时的最大收益
buy[i] = max(buy[i-1],sell[i-1]-prices[i])
# 考虑第i天买股票的最大收益
sell[i] = max(sell[i-1],buy[i-1] + prices[i])
return sell[-1]