Backspace String Compare
Given two strings S andT, return if they are equal when both are typed into empty text editors.#means a backspace character.
Example
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
最优解就是
记录#的数目,反向遍历。
当遇到#大于0的时候就跳过下一个字符,并减少#的count
如果遇到的是字符,且#的count是0,就相互直接比较
i或者j应该同时到起点
比较不太好写
Code
Last updated