844. Backspace String Compare

Hill K·2022년 8월 30일
0

Algorithm

목록 보기
7/11

Example 1

Input: s = "ab#c", t = "ad#c"
Output: true
Explanation: Both s and t become "ac".

Example 2

Input: s = "ab##", t = "c#d#"
Output: true
Explanation: Both s and t become "".

조건

1 <= s.length, t.length <= 200
s and t only contain lowercase letters and '#' characters.

class Solution:
    def backspaceCompare(self, s: str, t: str) -> bool:
        def process(s):
            s_lst = []
            for i in s:
                if i == "#":
                    if s_lst != []:
                        s_lst.pop()
                else:
                    s_lst.append(i)
            return s_lst
        return process(s) == process(t)
profile
안녕하세요

0개의 댓글