Skip to content

Commit ae04a46

Browse files
authored
Create Leetcode_1910.cpp
Use the solution block to submit code on Leetcode
1 parent c9ba1eb commit ae04a46

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

Leetcode_1910.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
}

0 commit comments

Comments
 (0)