Class Solution
java.lang.Object
g1901_2000.s1910_remove_all_occurrences_of_a_substring.Solution
1910 - Remove All Occurrences of a Substring.<p>Medium</p>
<p>Given two strings <code>s</code> and <code>part</code>, perform the following operation on <code>s</code> until <strong>all</strong> occurrences of the substring <code>part</code> are removed:</p>
<ul>
<li>Find the <strong>leftmost</strong> occurrence of the substring <code>part</code> and <strong>remove</strong> it from <code>s</code>.</li>
</ul>
<p>Return <code>s</code> <em>after removing all occurrences of</em> <code>part</code>.</p>
<p>A <strong>substring</strong> is a contiguous sequence of characters in a string.</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> s = “daabcbaabcbc”, part = “abc”</p>
<p><strong>Output:</strong> “dab”</p>
<p><strong>Explanation:</strong> The following operations are done:</p>
<ul>
<li>
<p>s = “da<strong>abc</strong>baabcbc”, remove “abc” starting at index 2, so s = “dabaabcbc”.</p>
</li>
<li>
<p>s = “daba<strong>abc</strong>bc”, remove “abc” starting at index 4, so s = “dababc”.</p>
</li>
<li>
<p>s = “dab<strong>abc</strong>”, remove “abc” starting at index 3, so s = “dab”. Now s has no occurrences of “abc”.</p>
</li>
</ul>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> s = “axxxxyyyyb”, part = “xy”</p>
<p><strong>Output:</strong> “ab”</p>
<p><strong>Explanation:</strong> The following operations are done:</p>
<ul>
<li>
<p>s = “axxx<strong>xy</strong>yyyb”, remove “xy” starting at index 4 so s = “axxxyyyb”.</p>
</li>
<li>
<p>s = “axx<strong>xy</strong>yyb”, remove “xy” starting at index 3 so s = “axxyyb”.</p>
</li>
<li>
<p>s = “ax<strong>xy</strong>yb”, remove “xy” starting at index 2 so s = “axyb”.</p>
</li>
<li>
<p>s = “a<strong>xy</strong>b”, remove “xy” starting at index 1 so s = “ab”. Now s has no occurrences of “xy”.</p>
</li>
</ul>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= s.length <= 1000</code></li>
<li><code>1 <= part.length <= 1000</code></li>
<li><code>s</code> and <code>part</code> consists of lowercase English letters.</li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
removeOccurrences
-