Skip to content

844 Backspace String Compare

844. Backspace String Compare

题目: https://leetcode.com/problems/backspace-string-compare/

难度:

Easy

思路

就看一下两个字符串变化完之后是不是相等就行了, - 时间复杂度:O(n) - 空间复杂度:O(n)

class Solution(object):
    def backspaceCompare(self, S, T):
        """
        :type S: str
        :type T: str
        :rtype: bool
        """
        def afterChange(s): 
            res = ''
            for i in s:
                if i == '#':
                    res = '' if len(res) == 0 else res[:-1]
                else:
                    res += i
            return res
        return afterChange(S) == afterChange(T)

我们一直在努力

apachecn/AiLearning

【布客】中文翻译组