Compare Two Backspace-Edited Strings. Type each string into a separate empty editor. Lowercase letters append themselves and # deletes the latest remaining character, doing nothing when the editor is empty.
### Problem
Type each string into a separate empty editor. Lowercase letters append themselves and # deletes the latest remaining character, doing nothing when the editor is empty. Return whether the two final texts are equal.
```cpp
class Solution {
public:
bool backspaceCompare(string s, string t);
};
```
### Examples
**Example 1:**
```text
s = "xy#z", t = "xz"
Output: true
Explanation: Backspacing y leaves xz in both editors.
```
**Example 2:**
```text
s = "##a", t = "#b"
Output: false
Explanation: Extra leading backspaces leave final texts a and b.
```
### Constraints
- Each input has 1 through 200 characters.
- Only lowercase English letters and # occur.
### Contract considerations
Handle backspacing an empty editor without inventing negative text length.
```hint Read the boundary condition
How many earlier letters are erased by the backspaces seen to the right?
```
### Boundary reminders
Handle backspacing an empty editor without inventing negative text length.
### Optional extensions
- Can you compare the final texts in linear time using constant extra storage?
Overview: Compare Two Backspace-Edited Strings. Type each string into a separate empty editor. Lowercase letters append themselves and # deletes the latest remaining character, doing nothing when the editor is empty.
Type each string into a separate empty editor. Lowercase letters append themselves and # deletes the latest remaining character, doing nothing when the editor is empty. Return whether the two final texts are equal.
class Solution {
public:
bool backspaceCompare(string s, string t);
};
Examples
Example 1:
s = "xy#z", t = "xz"
Output: true
Explanation: Backspacing y leaves xz in both editors.
Example 2:
s = "##a", t = "#b"
Output: false
Explanation: Extra leading backspaces leave final texts a and b.
Constraints
Each input has 1 through 200 characters.
Only lowercase English letters and # occur.
Contract considerations
Handle backspacing an empty editor without inventing negative text length.
Boundary reminders
Handle backspacing an empty editor without inventing negative text length.
Optional extensions
Can you compare the final texts in linear time using constant extra storage?