Grokking the Coding Interview: Patterns for Coding Questions
Ask Author
Back to course home

0% completed

Vote For New Content
Arturo Calderón
If the space complexity is not an issue this can be solved more easily by using stacks

Arturo Calderón

Aug 14, 2023

class Solution: def ApplyBackspaces(self, string): stack = [] for c in string: if c == '#': if len(stack) > 0: stack.pop() else: stack.append(c) return ''.join(stack) def compare(self, string1, string2): return self.ApplyBackspaces(string1) == self.ApplyBackspaces(string2)

8

0

Comments
Comments

On this page