标准双指针解法:
class Solution:
def backspaceCompare(self, s: str, t: str) -> bool:
'''
若x后有#,则x消失
'''
def str_change(s: str):
if not s:
return '1'
s = list(s)
slow = fast = 0
while fast < len(s):
if s[fast] != '#':
s[slow] = s[fast]
slow += 1
elif s[fast] == '#' and slow > 0: # 存在前面已经消完了但是还有#的情况,slow到0了就不能再-1
slow -= 1
fast += 1
return s[:slow]
return str_change(s) == str_change(t)