Skip to content

Commit 975c896

Browse files
committed
DAY62
1 parent 673cd92 commit 975c896

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

Day62/index.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* @param {number[]} nums
3+
* @return {number}
4+
*/
5+
var maxCoins = function (nums) {
6+
let N = nums.length;
7+
if (N == 0) return 0;
8+
9+
let opt = new Array(N).fill(0).map(() => new Array(N).fill(0));
10+
11+
for (let len = 0; len < N; len++) {
12+
13+
for (let i = 0; i + len < N; i++) {
14+
let j = i + len;
15+
16+
for (let k = i; k <= j; k++) {
17+
18+
let left_num = i === 0 ? 1 : nums[i - 1];
19+
let right_num = j === N - 1 ? 1 : nums[j + 1];
20+
21+
let left_opt = k == i ? 0 : opt[i][k - 1];
22+
let right_opt = k == j ? 0 : opt[k + 1][j]
23+
24+
opt[i][j] = Math.max(
25+
opt[i][j],
26+
left_num * nums[k] * right_num + left_opt + right_opt
27+
28+
)
29+
30+
}
31+
}
32+
}
33+
return opt[0][N - 1]
34+
};

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,4 +139,6 @@ If you are loving solving problems in leetcode, please contact me to enjoy it to
139139

140140
|Day 60| [80. Remove Duplicates from Sorted Array II](https://leetcode.com/problems/remove-duplicates-from-sorted-array-ii/) | [javascript]()|[:memo:](https://leetcode.com/problems/remove-duplicates-from-sorted-array-ii/)|Medium|
141141

142-
|Day 61| [865. Smallest Subtree with all the Deepest Nodes](https://leetcode.com/problems/smallest-subtree-with-all-the-deepest-nodes/) | [javascript]()|[:memo:](https://leetcode.com/problems/smallest-subtree-with-all-the-deepest-nodes/)|Medium|
142+
|Day 61| [865. Smallest Subtree with all the Deepest Nodes](https://leetcode.com/problems/smallest-subtree-with-all-the-deepest-nodes/) | [javascript]()|[:memo:](https://leetcode.com/problems/smallest-subtree-with-all-the-deepest-nodes/)|Medium|
143+
144+
|Day 62| [312. Burst Balloons](https://leetcode.com/problems/burst-balloons/) | [javascript]()|[:memo:](https://leetcode.com/problems/burst-balloons/)|Hard|

0 commit comments

Comments
 (0)