Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 7575cfd

Browse files
更正了188股票问题一维数组空间优化的java代码
1 parent 6bc2480 commit 7575cfd

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

‎problems/0188.买卖股票的最佳时机IV.md

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ public:
165165

166166
## 其他语言版本
167167

168-
Java:
168+
### Java
169169

170170
```java
171171
// 版本一: 三维 dp数组
@@ -228,9 +228,9 @@ class Solution {
228228
if(k == 0){
229229
return 0;
230230
}
231-
// 其实就是123题的扩展,123题只用记录2天的状态
232-
// 这里记录k天的状态就行了
233-
// 每天都有买入,卖出两个状态,所以要乘 2
231+
// 其实就是123题的扩展,123题只用记录2次交易的状态
232+
// 这里记录k次交易的状态就行了
233+
// 每次交易都有买入,卖出两个状态,所以要乘 2
234234
int[] dp = new int[2 * k];
235235
// 按123题解题格式那样,做一个初始化
236236
for(int i = 0; i < dp.length / 2; i++){
@@ -246,15 +246,15 @@ class Solution {
246246
dp[j + 1] = Math.max(dp[j + 1], dp[j] + prices[i - 1]);
247247
}
248248
}
249-
// 返回最后一天卖出状态的结果就行了
249+
// 返回最后一次交易卖出状态的结果就行了
250250
return dp[dp.length - 1];
251251
}
252252
}
253253
```
254254

255-
256-
Python:
255+
### Python
257256
版本一
257+
258258
```python
259259
class Solution:
260260
def maxProfit(self, k: int, prices: List[int]) -> int:
@@ -285,8 +285,9 @@ class Solution:
285285
dp[j] = max(dp[j],dp[j-1]+prices[i])
286286
return dp[2*k]
287287
```
288-
Go:
288+
### Go
289289
版本一:
290+
290291
```go
291292
// 买卖股票的最佳时机IV 动态规划
292293
// 时间复杂度O(kn) 空间复杂度O(kn)
@@ -356,10 +357,7 @@ func max(a,b int)int{
356357
}
357358
```
358359

359-
360-
361-
362-
Javascript:
360+
### Javascript
363361

364362
```javascript
365363
// 方法一:动态规划

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /