# 1910. Remove All Occurrences of a Substring ###### tags: `Leetcode` `Medium` `String` `Two Pointers` Link: https://leetcode.com/problems/remove-all-occurrences-of-a-substring/description/ ## 思路 [思路参考](https://leetcode.com/problems/remove-all-occurrences-of-a-substring/solutions/1298766/c-simple-solution-faster-than-100/) 构建一个新字串 随着遍历s,把每一个新字母加进新字符串 然后检查新字符串是不是以part结尾 如果是的话就把part删掉 ## Code ```python= class Solution: def removeOccurrences(self, s: str, part: str) -> str: t = "" j = 0 for i in range(len(s)): t += s[i] if t.endswith(part): t = t[:-len(part)] return t ```