You are given an integer array nums.
You must repeatedly apply the following merge operation until no more changes can be made:
After each merge operation, the array size decreases by 1. Repeat the process on the updated array until no more changes can be made.
Return the final array after all possible merge operations.
Example 1:
Input: nums = [3,1,1,2]
Output: [3,4]
Explanation:
1 + 1 = 2, resulting in [3, 2, 2].2 + 2 = 4, resulting in [3, 4].[3, 4].Example 2:
Input: nums = [2,2,4]
Output: [8]
Explanation:
2 + 2 = 4, resulting in [4, 4].4 + 4 = 8, resulting in [8].Example 3:
Input: nums = [3,7,5]
Output: [3,7,5]
Explanation:
There are no adjacent equal elements in the array, so no operations are performed.
Constraints:
1 <= nums.length <= 1051 <= nums[i] <= 105Loading editor...
[3,1,1,2]