Python3 | Time: O(N+M), Space: O(N+M) | Easy to understand, useful comments | For loop
Time Complexity: O(N+M) where N=size of string s and M=size of string t\nSpace Complexity: O(N+M) because we create two new strings\n\nWe "clean" the strings an
**Time Complexity: O(N+M)** where N=size of string s and M=size of string t\n**Space Complexity: O(N+M)** because we create two new strings\n\nWe "clean" the strings and compare them to each other,\nLet me know if it was helpful and rate to help other people see it!\n\n*Note: This isn\'t the optimal solution, but found this approach easier to implement and understand\n(T: O(N+M), S: O(1) is the optimal solution, look for a Two-pointers approach) *\n\n```\nclass Solution:\n    def backspaceCompare(self, s: str, t: str) -> bool:\n        \n        #reverse strings (easier to work with?) O(N)\n        s=s[::-1]\n        t=t[::-1]\n        \n        s=self.clean_string(s)\n        t=self.clean_string(t)\n        \n        return s == t\n        \n    \n    #Helper function, removes \'#\' and their linked-characters (backspace action)\n    def clean_string(self, s:str) -> str:\n        new_s=\'\'\n        s_repeat=0\n        t_repeat=0\n        \n        #traverse string and add characters to new string\n            #skips the add if the character is \'#\' or it\'s linked-characters (backspace action)\n        for i in range(len(s)):\n            if s[i] == \'#\':\n                s_repeat+=1\n            elif s_repeat>0:\n                s_repeat-=1\n            else:\n                new_s+=s[i]\n        return new_s\n    \n    #Time complexity: O(N+M)\n    #Space Complexity: O(N+M)\n```
['Python3']