파비의 매일매일 공부기록

Today's Challenge 본문

Problem Solving/LeetCode

Today's Challenge

fabichoi 2022. 5. 1. 23:45

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

 

Backspace String Compare - LeetCode

Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

leetcode.com

처음엔 뭔 문제여.. 했는데 그냥 리스트로 구현하면 되는 거였음.

다른 사람의 풀이를 보니 @staticmethod 어노테이션 써서 구현하는 거 같긴 한데.. 크게 차이는 없을 듯?

class Solution:
    def backspaceCompare(self, s: str, t: str) -> bool:
        ss, tt = [], []
        
        for i in range(len(s)):
            if s[i] != '#':
                ss.append(s[i])
                continue
            if ss:
                ss.pop()            
        
        for i in range(len(t)):
            if t[i] != '#':
                tt.append(t[i])
                continue
            if tt:
                tt.pop()
                
        return ss == tt
반응형

'Problem Solving > LeetCode' 카테고리의 다른 글

Today's Challenge  (0) 2022.05.03
Today's Challenge  (0) 2022.05.02
Today's Challenge  (0) 2022.04.30
Today's Challenge  (0) 2022.04.29
Today's Challenge  (0) 2022.04.28
Comments