class Solution:
    def backspaceCompare(self, S: str, T: str) -> bool:
        s = self.simulate(S)
        t = self.simulate(T)
        # print(s, t)
        return s == t

    def simulate(self,S):
        arr = list(S)
        result = []
        for each in arr:
            if each == '#':
                if len(result):
                    result.pop()
            else:
                result.append(each)
        return result


S = "ab#c"
T = "ad#c"
s = Solution().backspaceCompare(S, T)
print(s)