java.lang.Object
g1901_2000.s1910_remove_all_occurrences_of_a_substring.Solution

public class Solution extends Object
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 = &ldquo;daabcbaabcbc&rdquo;, part = &ldquo;abc&rdquo;</p> <p><strong>Output:</strong> &ldquo;dab&rdquo;</p> <p><strong>Explanation:</strong> The following operations are done:</p> <ul> <li> <p>s = &ldquo;da<strong>abc</strong>baabcbc&rdquo;, remove &ldquo;abc&rdquo; starting at index 2, so s = &ldquo;dabaabcbc&rdquo;.</p> </li> <li> <p>s = &ldquo;daba<strong>abc</strong>bc&rdquo;, remove &ldquo;abc&rdquo; starting at index 4, so s = &ldquo;dababc&rdquo;.</p> </li> <li> <p>s = &ldquo;dab<strong>abc</strong>&rdquo;, remove &ldquo;abc&rdquo; starting at index 3, so s = &ldquo;dab&rdquo;. Now s has no occurrences of &ldquo;abc&rdquo;.</p> </li> </ul> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> s = &ldquo;axxxxyyyyb&rdquo;, part = &ldquo;xy&rdquo;</p> <p><strong>Output:</strong> &ldquo;ab&rdquo;</p> <p><strong>Explanation:</strong> The following operations are done:</p> <ul> <li> <p>s = &ldquo;axxx<strong>xy</strong>yyyb&rdquo;, remove &ldquo;xy&rdquo; starting at index 4 so s = &ldquo;axxxyyyb&rdquo;.</p> </li> <li> <p>s = &ldquo;axx<strong>xy</strong>yyb&rdquo;, remove &ldquo;xy&rdquo; starting at index 3 so s = &ldquo;axxyyb&rdquo;.</p> </li> <li> <p>s = &ldquo;ax<strong>xy</strong>yb&rdquo;, remove &ldquo;xy&rdquo; starting at index 2 so s = &ldquo;axyb&rdquo;.</p> </li> <li> <p>s = &ldquo;a<strong>xy</strong>b&rdquo;, remove &ldquo;xy&rdquo; starting at index 1 so s = &ldquo;ab&rdquo;. Now s has no occurrences of &ldquo;xy&rdquo;.</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 Details

    • Solution

      public Solution()
  • Method Details