class Solution:
    def backspaceCompare(self, S: str, T: str) -> bool:
        #create a stack for both strings
        # add each letter to stack if next letter is '#', pop stack
        # compare stack and return True if equal

        def resultString(string):
            stack = []
            for letter in string:
                if letter != '#':
                    stack.append(letter)
                else:
                    if not stack:
                        continue
                    else:
                        stack.pop()
            return "".join(stack)
    
        return resultString(S) == resultString(T)
        
fd41b1d767b624577e7ce696f16cb765d90d458e
<mask token>

class Solution:
    <mask token>

class Solution:

    def backspaceCompare(self, S: str, T: str) ->bool:

        def resultString(string):
            stack = []
            for letter in string:
                if letter != '#':
                    stack.append(letter)
                elif not stack:
                    continue
                else:
                    stack.pop()
            return ''.join(stack)
        return resultString(S) == resultString(T)

class Solution:
    def backspaceCompare(self, S: str, T: str) -> bool:
        #create a stack for both strings
        # add each letter to stack if next letter is '#', pop stack
        # compare stack and return True if equal

        def resultString(string):
            stack = []
            for letter in string:
                if letter != '#':
                    stack.append(letter)
                else:
                    if not stack:
                        continue
                    else:
                        stack.pop()
            return "".join(stack)
    
        return resultString(S) == resultString(T)
        