class Solution {
public:
string clearStars(string s) {
priority_queue<char,vector<char>,greater<char>>pq;
stack<char>s1;
stack<char>s2;
for(int i=0;i<s.size();i++){
if(s[i]!='*'){
pq.push(s[i]);
s1.push(s[i]);
}else{
while(s1.top()!=pq.top()){
s2.push(s1.top());
s1.pop();
}
pq.pop();
s1.pop();
while(!s2.empty()){
s1.push(s2.top());
s2.pop();
}
}
}
string ans="";
while(!s1.empty()){
ans+=s1.top();
s1.pop();
}
reverse(ans.begin(),ans.end());
return 0;
}
};
报错:
terminate called after throwing an instance of 'std::logic_error'
what(): basic_string::_M_construct null not valid