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