-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1910.cpp
More file actions
38 lines (35 loc) · 858 Bytes
/
1910.cpp
File metadata and controls
38 lines (35 loc) · 858 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
27
28
29
30
31
32
33
34
35
36
37
38
class Solution {
public:
string removeOccurrences(string s, string part) {
stack<char>st;
string sa="";
int n=s.size(),m=part.size();
for(int i=0;i<n;i++){
st.push(s[i]);
if(st.size()>=m){
if(check(st,part)){
int c=m;
while(c--){
st.pop();
}
}
}
}
while(!st.empty()){
sa+=st.top();
st.pop();
}
reverse(sa.begin(), sa.end());
return sa;
}
bool check(stack<char> st, string part){
int i=part.size()-1;
while(i>=0 && st.top()==part[i]){
// if(st.top()==part[i]){
st.pop();
i--;
// }
}
return (i==-1);
}
};