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: BothSandTbecome"ac".
Example 2:
Input: S="ab##", T="c#d#"Output: true Explanation: BothSandTbecome"".
Example 3:
Input: S="a##c", T="#a#c"Output: true Explanation: BothSandTbecome"c".
Example 4:
Input: S="a#c", T="b"Output: false Explanation: Sbecomes"c"whileTbecomes"b".
Note:
- 1 <= S.length <= 200
- 1 <= T.length <= 200
- S and T only contain lowercase letters and '#' characters.
Follow up:
- Can you solve it in O(N) time and O(1) space?
给 2 个字符串,如果遇到 # 号字符,就回退一个字符。问最终的 2 个字符串是否完全一致。
这一题可以用栈的思想来模拟,遇到 # 字符就回退一个字符。不是 # 号就入栈一个字符。比较最终 2 个字符串即可。