Package g0301_0400.s0312_burst_balloons
Class Solution
java.lang.Object
g0301_0400.s0312_burst_balloons.Solution
312 - Burst Balloons.<p>Hard</p>
<p>You are given <code>n</code> balloons, indexed from <code>0</code> to <code>n - 1</code>. Each balloon is painted with a number on it represented by an array <code>nums</code>. You are asked to burst all the balloons.</p>
<p>If you burst the <code>i<sup>th</sup></code> balloon, you will get <code>nums[i - 1] * nums[i] * nums[i + 1]</code> coins. If <code>i - 1</code> or <code>i + 1</code> goes out of bounds of the array, then treat it as if there is a balloon with a <code>1</code> painted on it.</p>
<p>Return <em>the maximum coins you can collect by bursting the balloons wisely</em>.</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> nums = [3,1,5,8]</p>
<p><strong>Output:</strong> 167</p>
<p><strong>Explanation:</strong></p>
<pre><code> nums = [3,1,5,8] --> [3,5,8] --> [3,8] --> [8] --> []
coins = 3*1*5 + 3*5*8 + 1*3*8 + 1*8*1 = 167
</code></pre>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> nums = [1,5]</p>
<p><strong>Output:</strong> 10</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>n == nums.length</code></li>
<li><code>1 <= n <= 500</code></li>
<li><code>0 <= nums[i] <= 100</code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
maxCoins
public int maxCoins(int[] nums)
-