3561. Resulting String After Adjacent Removals
You are given a string
sconsisting of lowercase English letters.You must repeatedly perform the following operation while the string
shas at least two consecutive characters:
- Remove the leftmost pair of adjacent characters in the string that are consecutive in the alphabet, in either order (e.g.,
'a'and'b', or'b'and'a').- Shift the remaining characters to the left to fill the gap.
Return the resulting string after no more operations can be performed.
Note: Consider the alphabet as circular, thus
'a'and'z'are consecutive.
1 | class Solution { |