You are viewing a single comment's thread. Return to all comments →
here is a python solution with O(n) time and O(n) space in worse case; however, if the stack ends up being empty the space will be O(1)
def superReducedString(s): stack = [] for c in s: if not stack or stack[-1] != c: stack.append(c) else: stack.pop() if not stack: return "Empty String" return "".join(stack)
Seems like cookies are disabled on this browser, please enable them to open this website
Super Reduced String
You are viewing a single comment's thread. Return to all comments →
here is a python solution with O(n) time and O(n) space in worse case; however, if the stack ends up being empty the space will be O(1)