Skip to content

Commit 9cd6ff6

Browse files
refactor 312
1 parent 2154422 commit 9cd6ff6

File tree

1 file changed

+1
-25
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+1
-25
lines changed

src/main/java/com/fishercoder/solutions/_312.java

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,5 @@
11
package com.fishercoder.solutions;
22

3-
/**
4-
* 312. Burst Balloons
5-
*
6-
* Given n balloons, indexed from 0 to n-1.
7-
* Each balloon is painted with a number on it represented by array nums.
8-
* You are asked to burst all the balloons.
9-
* If the you burst balloon i you will get nums[left] * nums[i] * nums[right] coins.
10-
* Here left and right are adjacent indices of i. After the burst, the left and right then becomes adjacent.
11-
12-
Find the maximum coins you can collect by bursting the balloons wisely.
13-
14-
Note:
15-
(1) You may imagine nums[-1] = nums[n] = 1. They are not real therefore you can not burst them.
16-
(2) 0 ≤ n ≤ 500, 0 ≤ nums[i] ≤ 100
17-
18-
Example:
19-
20-
Given [3, 1, 5, 8]
21-
22-
Return 167
23-
24-
nums = [3,1,5,8] --> [3,5,8] --> [3,8] --> [8] --> []
25-
coins = 3*1*5 + 3*5*8 + 1*3*8 + 1*8*1 = 167
26-
*/
273
public class _312 {
284

295
public static class Solution1 {
@@ -43,7 +19,7 @@ public int maxCoins(int[] iNums) {
4319
int right = left + k;
4420
for (int i = left + 1; i < right; ++i) {
4521
dp[left][right] = Math.max(dp[left][right],
46-
nums[left] * nums[i] * nums[right] + dp[left][i] + dp[i][right]);
22+
nums[left] * nums[i] * nums[right] + dp[left][i] + dp[i][right]);
4723
}
4824
}
4925
}

0 commit comments

Comments
 (0)