Given two strings s and t, return true if they are equal when both are typed into empty text editors, where '#' means a backspace character. Backspacing an empty text leaves it empty. Follow-up: solve it in O(n) time and O(1) space.
Given two strings s and t, return true if they are equal when both are typed into empty text editors, where '#' means a backspace character. Backspacing an empty text leaves it empty. Follow-up: solve it in O(n) time and O(1) space.
Example 1:
Input: {"s":"ab#c","t":"ad#c"}
Output: true
Constraints:
1≤s.length,t.length≤200
s and t only contain lowercase letters and '#' characters.
Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result
Run code to see results.
Input
arr ={"s":"ab#c","t":"ad#c"}
Scanning both strings from the right
'#' backspace
erased
survivor
s
t
a
b
⌫
c
a
d
⌫
c
i 3
j 3
Backspaces owed
skip_s
0
skip_t
0
Each '#' adds one; the next letter to its left pays one back and is erased.