mirror of
				https://gitee.com/coder-xiaomo/leetcode-problemset
				synced 2025-11-04 19:53:12 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			45 lines
		
	
	
		
			2.2 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			45 lines
		
	
	
		
			2.2 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
<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> </p>
 | 
						||
<p><strong>Example 1:</strong></p>
 | 
						||
 | 
						||
<pre>
 | 
						||
<strong>Input:</strong> s = "daabcbaabcbc", part = "abc"
 | 
						||
<strong>Output:</strong> "dab"
 | 
						||
<strong>Explanation</strong>: The following operations are done:
 | 
						||
- s = "da<strong><u>abc</u></strong>baabcbc", remove "abc" starting at index 2, so s = "dabaabcbc".
 | 
						||
- s = "daba<strong><u>abc</u></strong>bc", remove "abc" starting at index 4, so s = "dababc".
 | 
						||
- s = "dab<strong><u>abc</u></strong>", remove "abc" starting at index 3, so s = "dab".
 | 
						||
Now s has no occurrences of "abc".
 | 
						||
</pre>
 | 
						||
 | 
						||
<p><strong>Example 2:</strong></p>
 | 
						||
 | 
						||
<pre>
 | 
						||
<strong>Input:</strong> s = "axxxxyyyyb", part = "xy"
 | 
						||
<strong>Output:</strong> "ab"
 | 
						||
<strong>Explanation</strong>: The following operations are done:
 | 
						||
- s = "axxx<strong><u>xy</u></strong>yyyb", remove "xy" starting at index 4 so s = "axxxyyyb".
 | 
						||
- s = "axx<strong><u>xy</u></strong>yyb", remove "xy" starting at index 3 so s = "axxyyb".
 | 
						||
- s = "ax<strong><u>xy</u></strong>yb", remove "xy" starting at index 2 so s = "axyb".
 | 
						||
- s = "a<strong><u>xy</u></strong>b", remove "xy" starting at index 1 so s = "ab".
 | 
						||
Now s has no occurrences of "xy".
 | 
						||
</pre>
 | 
						||
 | 
						||
<p> </p>
 | 
						||
<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>
 |