Skip to content

Latest commit

 

History

History
38 lines (27 loc) · 699 Bytes

844._Backspace_String_Compare.md

File metadata and controls

38 lines (27 loc) · 699 Bytes

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)