Gary Lai
  • Home
  • About
Sign in Subscribe

844. Backspace String Compare

Last updated on  Apr 2, 2025

844. Backspace String Compare

class Solution:
    def backspaceCompare(self, s: str, t: str) -> bool:
        
        a = []
        for i in range(len(s)):
            if s[i] == '#':
                if len(a) > 0:
                    a.pop()
            else:
                a.append(s[i])
        
        b = []
        for i in range(len(t)):
            if t[i] == '#':
                if len(b) > 0:
                    b.pop()
            else:
                b.append(t[i])
        
        return ''.join(a) == ''.join(b)

        
Previous 24. Swap Nodes in Pairs
Next 71. Simplify Path
Gary Lai © 2025
  • Sign up
Powered by Ghost