diff --git a/problems/0188.买卖股票的最佳时机IV.md b/problems/0188.买卖股票的最佳时机IV.md index 0e898b43..537ccd4a 100644 --- a/problems/0188.买卖股票的最佳时机IV.md +++ b/problems/0188.买卖股票的最佳时机IV.md @@ -165,7 +165,7 @@ public: ## 其他语言版本 -Java: +### Java ```java // 版本一: 三维 dp数组 @@ -228,9 +228,9 @@ class Solution { if(k == 0){ return 0; } - // 其实就是123题的扩展,123题只用记录2天的状态 - // 这里记录k天的状态就行了 - // 每天都有买入,卖出两个状态,所以要乘 2 + // 其实就是123题的扩展,123题只用记录2次交易的状态 + // 这里记录k次交易的状态就行了 + // 每次交易都有买入,卖出两个状态,所以要乘 2 int[] dp = new int[2 * k]; // 按123题解题格式那样,做一个初始化 for(int i = 0; i < dp.length / 2; i++){ @@ -246,15 +246,15 @@ class Solution { dp[j + 1] = Math.max(dp[j + 1], dp[j] + prices[i - 1]); } } - // 返回最后一天卖出状态的结果就行了 + // 返回最后一次交易卖出状态的结果就行了 return dp[dp.length - 1]; } } ``` - -Python: +### Python 版本一 + ```python class Solution: def maxProfit(self, k: int, prices: List[int]) -> int: @@ -285,8 +285,9 @@ class Solution: dp[j] = max(dp[j],dp[j-1]+prices[i]) return dp[2*k] ``` -Go: +### Go 版本一: + ```go // 买卖股票的最佳时机IV 动态规划 // 时间复杂度O(kn) 空间复杂度O(kn) @@ -356,10 +357,7 @@ func max(a,b int)int{ } ``` - - - -Javascript: +### Javascript ```javascript // 方法一:动态规划