-
45. Backspace String CompareProblem Solving 2022. 12. 31. 20:49728x90
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
입력받은 두 개의 문자열에서 #을 backspace로 치환하여 문자열을 새로 만든 후 서로 일치하는지 비교하는 문제
class Solution: def backspaceCompare(self, s: str, t: str) -> bool: s1 = "" for i in s: if i != "#": s1 = s1 + i else: s1 = s1[:-1] t1 = "" for i in t: if i != "#": t1 = t1 + i else: t1 = t1[:-1] if s1 == t1: return True return False
파이썬의 최대 장점 중 하나인 문자열 파싱을 이용하면 쉽게 풀 수 있다.
'Problem Solving' 카테고리의 다른 글
47. 단어 공부 (0) 2022.12.31 46. Student Attendance Record I (0) 2022.12.31 44. JadenCase 문자열 만들기 (0) 2022.12.31 43. Detemine if String Halves Are Alike (0) 2022.12.31 42. Valid Perfect Square (0) 2022.12.31