leetcode——844. 比较含退格的字符串

class Solution(object):
    def backspaceCompare(self, S, T):
        """
        :type S: str
        :type T: str
        :rtype: bool
        """
        stack1=[]
        stack2=[]
        for i in S:
            if i!='#':
                stack1.append(i)
            else:
                if stack1!=[]:
                    stack1.pop()
        for j in T:
            if j!='#':
                stack2.append(j)
            else:
                if stack2 != []:
                    stack2.pop()
        return stack1==stack2
执行用时 :16 ms, 在所有 python 提交中击败了93.78%的用户
内存消耗 :11.8 MB, 在所有 python 提交中击败了19.05%的用户
 
——2019.11.2

猜你喜欢

转载自www.cnblogs.com/taoyuxin/p/11783180.html