File tree Expand file tree Collapse file tree 1 file changed +10
-12
lines changed Expand file tree Collapse file tree 1 file changed +10
-12
lines changed Original file line number Diff line number Diff line change @@ -165,7 +165,7 @@ public:
165
165
166
166
## 其他语言版本
167
167
168
- Java:
168
+ ### Java
169
169
170
170
``` java
171
171
// 版本一: 三维 dp数组
@@ -228,9 +228,9 @@ class Solution {
228
228
if (k == 0 ){
229
229
return 0 ;
230
230
}
231
- // 其实就是123题的扩展,123题只用记录2天的状态
232
- // 这里记录k天的状态就行了
233
- // 每天都有买入 ,卖出两个状态,所以要乘 2
231
+ // 其实就是123题的扩展,123题只用记录2次交易的状态
232
+ // 这里记录k次交易的状态就行了
233
+ // 每次交易都有买入 ,卖出两个状态,所以要乘 2
234
234
int [] dp = new int [2 * k];
235
235
// 按123题解题格式那样,做一个初始化
236
236
for (int i = 0 ; i < dp. length / 2 ; i++ ){
@@ -246,15 +246,15 @@ class Solution {
246
246
dp[j + 1 ] = Math . max(dp[j + 1 ], dp[j] + prices[i - 1 ]);
247
247
}
248
248
}
249
- // 返回最后一天卖出状态的结果就行了
249
+ // 返回最后一次交易卖出状态的结果就行了
250
250
return dp[dp. length - 1 ];
251
251
}
252
252
}
253
253
```
254
254
255
-
256
- Python:
255
+ ### Python
257
256
版本一
257
+
258
258
``` python
259
259
class Solution :
260
260
def maxProfit (self , k : int , prices : List[int ]) -> int :
@@ -285,8 +285,9 @@ class Solution:
285
285
dp[j] = max (dp[j],dp[j- 1 ]+ prices[i])
286
286
return dp[2 * k]
287
287
```
288
- Go:
288
+ ### Go
289
289
版本一:
290
+
290
291
``` go
291
292
// 买卖股票的最佳时机IV 动态规划
292
293
// 时间复杂度O(kn) 空间复杂度O(kn)
@@ -356,10 +357,7 @@ func max(a,b int)int{
356
357
}
357
358
```
358
359
359
-
360
-
361
-
362
- Javascript:
360
+ ### Javascript
363
361
364
362
``` javascript
365
363
// 方法一:动态规划
You can’t perform that action at this time.
0 commit comments