Remove adjacent, repeated characters in a given string, leaving only two characters for each group of such characters. The characters in the string are sorted in ascending order.
Examples
“aaaabbbc” is transferred to “aabbc”
class Solution(object):
def deDup(self, input):
if not input or len(input) < 2:
return input
lst = list(input)
left,right = 2,2
while right < len(lst):
if lst[right] != lst[left-2]:
lst[left] = lst[right]
left += 1
right += 1
return ''.join(lst[:left])