思路:普通的栈
class Solution {
public:bool isValid(string s) {
stack<char> the_stack;
for(int i=0;i<s.size();++i){
if(s[i]=='('|| s[i]=='{'|| s[i]=='['){
the_stack.push(s[i]);
}else if(!the_stack.empty()){
char pre=the_stack.top();
if( (s[i]==')' && pre=='(') || (s[i]==']' && pre=='[') || (s[i]=='}' && pre=='{') ){
the_stack.pop();
}else{
return false;
}
}else{
return false;
}
}
if(the_stack.empty())
return true;
else
return false;
}
};