AlgoLounge

Backspace String Compare

easy

Given two strings s and t, return true if they are equal when both are typed into empty text editors. '#' means a backspace character.

Note that after backspacing an empty text, the text will continue empty.

Examples

Example 1

Input:  s = "ab#c", t = "ad#c"
Output: true

Both s and t become "ac".

Example 2

Input:  s = "ab##", t = "c#d#"
Output: true

Both s and t become "".

Example 3

Input:  s = "a#c", t = "b"
Output: false

s becomes "c" while t becomes "b".

Constraints

  • 1 <= s.length, t.length <= 200
  • s and t only contain lowercase letters and '#' characters.
TypeScript
Loading editor…
List of test cases (10)
Case 1
s = "ab#c"
t = "ad#c"
Case 2
s = "ab##"
t = "c#d#"
Case 3
s = "a#c"
t = "b"
Case 4
s = "a##c"
t = "#a#c"
Case 5
s = "abc"
t = "abc"
Case 6
s = "###"
t = ""
Case 7
s = "bxj##tw"
t = "bxo#j##tw"
Case 8
s = "ab#c#d"
t = "ad#c#d"
Case 9
s = "a"
t = "b"
Case 10
s = "xywrrmp"
t = "xywrrmu#p"