> For the complete documentation index, see [llms.txt](https://nataliekung.gitbook.io/ladder_code/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://nataliekung.gitbook.io/ladder_code/qiang-hua-4-shuang-zhi-zhen-ff09/backspace-string-compare.md).

# Backspace String Compare

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

**Example 1:**

```
Input: 
S = 
"ab#c"
, T = 
"ad#c"
Output: 
true

Explanation
: Both S and T become "ac".
```

**Example 2:**

```
Input: 
S = 
"ab##"
, T = 
"c#d#"
Output: 
true

Explanation
: Both S and T become "".
```

**Example 3:**

```
Input: 
S = 
"a##c"
, T = 
"#a#c"
Output: 
true

Explanation
: Both S and T become "c".
```

**Example 4:**

```
Input: 
S = 
"a#c"
, T = 
"b"
Output: 
false

Explanation
: S becomes "c" while T becomes "b".
```

Note:

```
1 <= S.length <= 200
1 <= T.length <= 200
S and T only contain lowercase letters and '#' characters.
```

分析

栈内只加字母，不加#，遇到‘#’，抵消栈内char，字母的话加入。 最后比较S,T剩下的东西

```
class Solution:
    def backspaceCompare(self, S: str, T: str) -> bool:
        return self.getChar(S) == self.getChar(T)

    def getChar(self, S: str) -> str:
        stack = []
        for i in S:
            if stack and i == '#':
                stack.pop()
            elif i.isalpha():
                stack.append(i)
        return ''.join(stack)
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://nataliekung.gitbook.io/ladder_code/qiang-hua-4-shuang-zhi-zhen-ff09/backspace-string-compare.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
