728x90
난이도 : medium
문자열 s의 part 문자열을 왼쪽 부터 하나씩 제거하는 문제.
맨 처음에는 그냥 import re 및 re.sub을 통해서 제거했으나, 한번에 제거하는 문제가 아니었다.
class Solution:
def removeOccurrences(self, s: str, part: str) -> str:
while part in s:
s = s.replace(part, "", 1)
return s
replace로 part를 빈 문자열로 바꾸고, 왼쪽부터 하나만 바꾼다는 while문으로 해결
Runtime : 0ms
Memory : 17.94MB
728x90
'코딩 공부 > Leetcode' 카테고리의 다른 글
[Leetcode / Python] 2364. Count Number of Bad Pairs (0) | 2025.02.13 |
---|---|
[Leetcode / Python] 3174. Clear Digits (0) | 2025.02.12 |
[Python] 206. Reverse Linked List (0) | 2025.02.11 |
[Python] 19. Remove Nth Node From End of List (0) | 2025.02.10 |
[Python] 160. Intersection of Two Linked Lists (0) | 2025.02.09 |