简单题。注意python的s[:-1]在s == ''时,也是生效的。(返回'')

class Solution:
    def backspaceCompare(self, S: str, T: str) -> bool:
        normS = self.normalize(S)
        normT = self.normalize(T)
        return normS == normT

    def normalize(self, s: str) -> str:
        normStr = ''
        for char in s:
            if char == '#':
                normStr = normStr[:-1]
            else:
                normStr += char
        return normStr

  

相关文章:

  • 2022-12-23
  • 2021-11-16
  • 2022-12-23
  • 2021-06-08
  • 2021-08-06
  • 2021-11-18
  • 2021-10-22
  • 2021-11-09
猜你喜欢
  • 2021-09-30
  • 2021-09-14
  • 2022-03-06
  • 2021-11-24
  • 2021-11-15
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案