---
# System prepended metadata

title: Leetcode 844. Backspace string compare

---

# Leetcode 844. Backspace string compare

## 使用棧進行字串比對

```python=
class Solution:
    def backspaceCompare(self, s: str, t: str) -> bool:
        def backSpace(string: str):
            stack = []
            for s in string:
                if s != "#":
                    stack.append(s)
                else:
                    if stack:
                        stack.pop()
            return stack
        return backSpace(s) == backSpace(t)
```
