问题描述
You are given n balloons, indexed from 0 to n - 1. Each balloon is painted with a number on it represented by an array nums. You are asked to burst all the balloons.
If you burst the ith balloon, you will get nums[left] * nums[i] * nums[right]
coins. Here left and right are adjacent indices of i. After the burst, the left and right then becomes adjacent.
Return the maximum coins you can collect by bursting the balloons wisely.
Example 1:
1 | Input: nums = [3,1,5,8] |
Example 2:
1 | Input: nums = [1,5] |
Constraints:
- n == nums.length
- 1 <= n <= 500
- 0 <= nums[i] <= 100
解题思路
1 | /** |
- 时间复杂度:O(n^3)
- 空间复杂度:O(n^2)