bumpsoo 2025-02-11 12:29:58 +00:00
parent 43527186ef
commit 362b79ae66

View file

@ -0,0 +1,15 @@
# https://leetcode.com/problems/remove-all-occurrences-of-a-substring
class Solution:
def removeOccurrences(self, s: str, part: str) -> str:
result = []
def is_part():
return "".join(result[-len(part):]) == part
for ch in s:
result.append(ch)
if len(result) >= len(part):
if is_part():
for _ in range(len(part)):
result.pop()
return "".join(result)