class Solution:
def maxProfit(self, prices: List[int]) -> int:
n = len(prices)
dp = [[0]*2 for _ in range(n)]
dp[0][0] = -prices[0]
for i in range(1,n):
dp[i][0] = max(dp[i-1][0],dp[i-1][1]-prices[i])
dp[i][1] = max(dp[i-1][1],dp[i-1][0]+prices[i])
return dp[n-1][1]
class Solution:
def maxProfit(self, prices: List[int]) -> int:
n = len(prices)
res = 0
#每个增加的小段
for i in range(1,n):
if prices[i] > prices[i-1]:
res += prices[i]-prices[i-1]
return res