1
class Solution {
2
public:
3
bool check(stack<char> st, string part) {
4
int n2 = part.length();
5
int j = n2 - 1;
6
while (j >= 0 and st.top() == part[j]) {
7
st.pop();
8
j--;
9
}
10
return (j == -1);
11
}
12
string removeOccurrences(string s, string part) {
13
int n1 = s.length(), n2 = part.length();
14
stack<char> st;
15
string str = "";
16
for (int i = 0; i < n1; ++i) {
17
st.push(s[i]);
18
if (st.size() >= n2) {
19
if (check(st, part)) {
20
int ct = n2;
21
while (ct--) {
22
st.pop();
23
}
24
}
25
}
26
}
27
string res = "";
28
while (!st.empty()) {
29
res += st.top();
30
st.pop();
31
}
32
reverse(res.begin(), res.end());
33
return res;
34
}
35
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0