> For the complete documentation index, see [llms.txt](https://adit0503.gitbook.io/leetcode/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://adit0503.gitbook.io/leetcode/x.-backspace-string-compare.md).

# X. Backspace String Compare

Easy

**Given two strings S and T, return if they are equal when both are typed into empty text editors. # means a backspace character.**

## :innocent: [**Solution**](https://leetcode.com/explore/featured/card/30-day-leetcoding-challenge/529/week-2/3291/)

{% tabs %}
{% tab title="O(s)" %}

```python
class Solution:
    def backspaceCompare(self, S: str, T: str) -> bool:
        
        temp_s = ''
        temp_t = ''
        
        for i,s in enumerate(S):
            if S[i] == '#':
                temp_s = temp_s[:-1]
            else:
                temp_s += s
                
        for j,t in enumerate(T):
            if T[j] == '#':
                temp_t = temp_t[:-1]
            else:
                temp_t += t

        return temp_s == temp_t
```

{% endtab %}
{% endtabs %}
