class Solution {
public:
bool isValid(string s) {
stack<char> stc;
map<char, char> m{{'(',')'}, {'[',']'}, {'{','}'}};
for(auto c:s){
if(!stc.empty() && c == m[stc.top()])
stc.pop();
else
stc.push(c);
}
return stc.empty();
}
};
class Solution {
public:
bool isValid(string s) {
stack<char> stc;
for(auto c:s){
if(c == 'c'){
if(stc.empty() || stc.top() != 'b') return false;
stc.pop();
if(stc.empty() || stc.top() != 'a') return false;
stc.pop();
}
else stc.push(c);
}
return stc.empty();
}
};