|
| 1 | +<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> |
| 2 | + |
| 3 | +<ul> |
| 4 | + <li>Find the <strong>leftmost</strong> occurrence of the substring <code>part</code> and <strong>remove</strong> it from <code>s</code>.</li> |
| 5 | +</ul> |
| 6 | + |
| 7 | +<p>Return <code>s</code><em> after removing all occurrences of </em><code>part</code>.</p> |
| 8 | + |
| 9 | +<p>A <strong>substring</strong> is a contiguous sequence of characters in a string.</p> |
| 10 | + |
| 11 | +<p> </p> |
| 12 | +<p><strong class="example">Example 1:</strong></p> |
| 13 | + |
| 14 | +<pre> |
| 15 | +<strong>Input:</strong> s = "daabcbaabcbc", part = "abc" |
| 16 | +<strong>Output:</strong> "dab" |
| 17 | +<strong>Explanation</strong>: The following operations are done: |
| 18 | +- s = "da<strong><u>abc</u></strong>baabcbc", remove "abc" starting at index 2, so s = "dabaabcbc". |
| 19 | +- s = "daba<strong><u>abc</u></strong>bc", remove "abc" starting at index 4, so s = "dababc". |
| 20 | +- s = "dab<strong><u>abc</u></strong>", remove "abc" starting at index 3, so s = "dab". |
| 21 | +Now s has no occurrences of "abc". |
| 22 | +</pre> |
| 23 | + |
| 24 | +<p><strong class="example">Example 2:</strong></p> |
| 25 | + |
| 26 | +<pre> |
| 27 | +<strong>Input:</strong> s = "axxxxyyyyb", part = "xy" |
| 28 | +<strong>Output:</strong> "ab" |
| 29 | +<strong>Explanation</strong>: The following operations are done: |
| 30 | +- s = "axxx<strong><u>xy</u></strong>yyyb", remove "xy" starting at index 4 so s = "axxxyyyb". |
| 31 | +- s = "axx<strong><u>xy</u></strong>yyb", remove "xy" starting at index 3 so s = "axxyyb". |
| 32 | +- s = "ax<strong><u>xy</u></strong>yb", remove "xy" starting at index 2 so s = "axyb". |
| 33 | +- s = "a<strong><u>xy</u></strong>b", remove "xy" starting at index 1 so s = "ab". |
| 34 | +Now s has no occurrences of "xy". |
| 35 | +</pre> |
| 36 | + |
| 37 | +<p> </p> |
| 38 | +<p><strong>Constraints:</strong></p> |
| 39 | + |
| 40 | +<ul> |
| 41 | + <li><code>1 <= s.length <= 1000</code></li> |
| 42 | + <li><code>1 <= part.length <= 1000</code></li> |
| 43 | + <li><code>s</code> and <code>part</code> consists of lowercase English letters.</li> |
| 44 | +</ul> |
0 commit comments