leetcode312题戳气球java实现
时间: 2023-05-22 12:06:19 浏览: 168
好的,以下是LeetCode 312题戳气球的Java实现:
```java
public class Solution {
public int maxCoins(int[] nums) {
int n = nums.length;
int[] newNums = new int[n+2];
for(int i=0; i<n; i++){
newNums[i+1] = nums[i];
}
newNums[0] = 1;
newNums[n+1] = 1;
int[][] dp = new int[n+2][n+2];
for(int len=1; len<=n; len++){
for(int i=1; i<=n-len+1; i++){
int j = i+len-1;
for(int k=i; k<=j; k++){
dp[i][j] = Math.max(dp[i][j], dp[i][k-1]+newNums[i-1]*newNums[k]*newNums[j+1]+dp[k+1][j]);
}
}
}
return dp[1][n];
}
}
```
希望对你有帮助!
阅读全文