Remove All Occurrences of a Substring
Given two strings s and part, perform the following operation on s until all occurrences of the substring part are removed:
- Find the leftmost occurrence of the substring
partand remove it froms.
Return s after removing all occurrences of part.
A substring is a contiguous sequence of characters in a string.
Example 1
Input
s = "daabcbaabcbc", part = "abc"Output
"dab"Removing the leftmost occurrence of "abc" repeatedly transforms "daabcbaabcbc" into "dab", which has no remaining occurrences of "abc".
Example 2
Input
s = "axxxxyyyyb", part = "xy"Output
"ab"Removing the leftmost occurrence of "xy" repeatedly transforms "axxxxyyyyb" into "ab", which has no remaining occurrences of "xy".
Constraints
- 1 <= s.length <= 1000
- 1 <= part.length <= 1000
- s and part consists of lowercase English letters.