#3834

Merge Adjacent Equal Elements

specialist · 995 · lc medium +32 · 41.9% accepted · 86 likes · top 23%

Description

Given an integer array nums, repeatedly scan for the leftmost pair of adjacent equal elements and replace that pair with a single element equal to their sum (shrinking the array by one). Continue applying this rule to the updated array until no adjacent equal elements remain. Return the final array.

Code

1
2
3