Online Python Compiler

class Solution: def solve(self, s): stack = [] i = 0 while i < len(s): if len(stack) and stack[-1] == s[i]: x = stack.pop() while i < len(s) and x == s[i]: i += 1 i -= 1 else: stack.append(s[i]) i += 1 return "".join(stack) ob = Solution() s = "xyyyxxz" print(ob.solve(s))