Given two strings
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.
Input: s = "ab#c", t = "ad#c" Output: true Explanation: Both s and t become "ac".
Input: s = "ab##", t = "c#d#" Output: true Explanation: Both s and t become "".
Input: s = "a##c", t = "#a#c" Output: true Explanation: Both s and t become "c".
Input: s = "a#c", t = "b" Output: false Explanation: s becomes "c" while t becomes "b".
1 <= s.length, t.length <= 200
tonly contain lowercase letters and
Follow up: Can you solve it in
O(n) time and
Solution in Python
class Solution: @staticmethod def build(keys): stack =  for i in keys: if i=="#": if stack: stack.pop() else: stack.append(i) return stack def backspaceCompare(self, S: str, T: str) -> bool: return self.build(T)==self.build(S)