class Solution:
def maxProfit(self , prices: List[int]) -> int:
if len == 0:
return 0
dp = [[0,0] for _ in range(len(prices))]
dp[0][0] = prices[0] #表示第i天买入股票情况下消费的现金
dp[0][1] = 0 #表示第i天不持有股票情况下持有的现金
for i in range(1, len(prices)):
dp[i][0] = min(dp[i-1][0], prices[i]) #尽量低价买入,所以取“今天之前持有股票的消费”和“第i天买入股票的消费”的min
dp[i][1] = max(dp[i-1][1], prices[i] - dp[i-1][0]) #尽量高价卖出,当天价格减去入手时价格,之前与第i天的max
return dp[-1][1]
# write code here