Skip to content

Commit 206715f

Browse files
committed
fix: solution
1 parent 9113d93 commit 206715f

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

solution/2200-2299/2218.Maximum Value of K Coins From Piles/README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,11 @@ function maxValueOfCoins(piles: number[][], k: number): number {
208208

209209
<!-- solution:start -->
210210

211-
### 方法二
211+
### 方法二:动态规划(空间优化)
212+
213+
我们可以发现,对于第 $i$ 组,我们只需要用到 $f[i - 1][j]$ 和 $f[i][j - h]$,因此我们可以将二维数组优化为一维数组。
214+
215+
时间复杂度 $O(k \times L)$,空间复杂度 $O(k)$。
212216

213217
<!-- tabs:start -->
214218

solution/2200-2299/2218.Maximum Value of K Coins From Piles/README_EN.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,11 @@ function maxValueOfCoins(piles: number[][], k: number): number {
204204

205205
<!-- solution:start -->
206206

207-
### Solution 2
207+
### Solution 2: Dynamic Programming (Space Optimization)
208+
209+
We can observe that for the $i$-th pile, we only need to use $f[i - 1][j]$ and $f[i][j - h]$, so we can optimize the two-dimensional array to a one-dimensional array.
210+
211+
The time complexity is $O(k \times L)$, and the space complexity is $O(k)$.
208212

209213
<!-- tabs:start -->
210214

0 commit comments

Comments
 (0)