122.M 买卖股票的最佳时机 II
思路
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])Code
func maxProfit(prices []int) int {
profit := 0
for i := 1; i < len(prices); i++ {
if prices[i]-prices[i-1] > 0 {
profit += prices[i] - prices[i-1]
}
}
return profit
}Last updated