forked from Hrudhay-H/Cpp_Algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLeetcode_1910.cpp
More file actions
26 lines (21 loc) · 886 Bytes
/
Copy pathLeetcode_1910.cpp
File metadata and controls
26 lines (21 loc) · 886 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <bits/stdc++.h> // Includes all standard C++ libraries
using namespace std;
class Solution {
public:
// Function to remove all occurrences of 'part' from string 's'
string removeOccurrences(string s, string part) {
// Keep removing 'part' from 's' as long as it is found in 's'
while (s.length() > 0 && s.find(part) < s.length()) {
s.erase(s.find(part), part.length()); // Erase the found substring
}
return s; // Return the modified string
}
};
int main() {
Solution sol; // Create an instance of the Solution class
// Example input string and part to remove
string s = "daabcbaabcbc", part = "abc";
// Call the function and print the result
cout << sol.removeOccurrences(s, part) << endl;
return 0; // Return 0 to indicate successful execution
}