Leetcode 2021 Solution
This article provides solution to leetcode question 2021 (remove-all-occurrences-of-a-substring)
Access this page by simply typing in "lcs 2021" in your browser address bar if you have bunnylol configured.
Leetcode Question Link
https://leetcode.com/problems/remove-all-occurrences-of-a-substring
Solution
class Solution:
def removeOccurrences(self, s: str, part: str) -> str:
ans = ""
for ch in s:
ans += ch
if len(ans) >= len(part) and ans[-len(part):] == part:
ans = ans[:-len(part)]
return ans