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
반응형