File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change 1+ #include < bits/stdc++.h> // Includes all standard C++ libraries
2+ using namespace std ;
3+
4+ class Solution {
5+ public:
6+ // Function to remove all occurrences of 'part' from string 's'
7+ string removeOccurrences (string s, string part) {
8+ // Keep removing 'part' from 's' as long as it is found in 's'
9+ while (s.length () > 0 && s.find (part) < s.length ()) {
10+ s.erase (s.find (part), part.length ()); // Erase the found substring
11+ }
12+ return s; // Return the modified string
13+ }
14+ };
15+
16+ int main () {
17+ Solution sol; // Create an instance of the Solution class
18+
19+ // Example input string and part to remove
20+ string s = " daabcbaabcbc" , part = " abc" ;
21+
22+ // Call the function and print the result
23+ cout << sol.removeOccurrences (s, part) << endl;
24+
25+ return 0 ; // Return 0 to indicate successful execution
26+ }
You can’t perform that action at this time.
0 commit comments