使用stack != []判断比len(stack) != 0要节省内存。
class Solution:
def backspaceCompare(self, S: str, T: str) -> bool:
def character(strList):
stack = []
for i in strList:
if i == "#" and stack != []:
stack.pop()
elif i != "#":
stack.append(i)
return stack
return character(S) == character(T)