1910. Remove All Occurrences of a Substring Medium

@problem@discussion
#String



1/**
2 * [1910] Remove All Occurrences of a Substring
3 *
4 * Given two strings s and part, perform the following operation on s until all occurrences of the substring part are removed:
5 * 
6 * 	Find the leftmost occurrence of the substring part and remove it from s.
7 * 
8 * Return s after removing all occurrences of part.
9 * A substring is a contiguous sequence of characters in a string.
10 *  
11 * Example 1:
12 * 
13 * Input: s = "daabcbaabcbc", part = "abc"
14 * Output: "dab"
15 * Explanation: The following operations are done:
16 * - s = "da<u>abc</u>baabcbc", remove "abc" starting at index 2, so s = "dabaabcbc".
17 * - s = "daba<u>abc</u>bc", remove "abc" starting at index 4, so s = "dababc".
18 * - s = "dab<u>abc</u>", remove "abc" starting at index 3, so s = "dab".
19 * Now s has no occurrences of "abc".
20 * 
21 * Example 2:
22 * 
23 * Input: s = "axxxxyyyyb", part = "xy"
24 * Output: "ab"
25 * Explanation: The following operations are done:
26 * - s = "axxx<u>xy</u>yyyb", remove "xy" starting at index 4 so s = "axxxyyyb".
27 * - s = "axx<u>xy</u>yyb", remove "xy" starting at index 3 so s = "axxyyb".
28 * - s = "ax<u>xy</u>yb", remove "xy" starting at index 2 so s = "axyb".
29 * - s = "a<u>xy</u>b", remove "xy" starting at index 1 so s = "ab".
30 * Now s has no occurrences of "xy".
31 * 
32 *  
33 * Constraints:
34 * 
35 * 	1 <= s.length <= 1000
36 * 	1 <= part.length <= 1000
37 * 	s​​​​​​ and part consists of lowercase English letters.
38 * 
39 */
40pub struct Solution {}
41
42// problem: https://leetcode.com/problems/remove-all-occurrences-of-a-substring/
43// discuss: https://leetcode.com/problems/remove-all-occurrences-of-a-substring/discuss/?currentPage=1&orderBy=most_votes&query=
44
45// submission codes start here
46
47impl Solution {
48    pub fn remove_occurrences(s: String, part: String) -> String {
49        String::new()
50    }
51}
52
53// submission codes end
54
55#[cfg(test)]
56mod tests {
57    use super::*;
58
59    #[test]
60    fn test_1910() {
61    }
62}
63


Back
© 2025 bowen.ge All Rights Reserved.