class Solution {
public:
bool isValid(string s) {
int r1 = 0, r2 = 0, r3 = 0;
char temp;
stack<char> stk;
for(int i = 0; i < s.size(); ++i){
if(s[i] == '(' || s[i] == '[' || s[i] =='{'){
stk.push(s[i]);
}else if (s[i] == ')'){
if(!stk.empty()){
temp = stk.top();
if(temp != '(') return false;
stk.pop();
}else{
return false;
}
}else if(s[i] == ']'){
if(!stk.empty()){
temp = stk.top();
if(temp != '[') return false;
stk.pop();
}else{
return false;
}
}else if(s[i] == '}'){
if(!stk.empty()){
temp = stk.top();
if(temp != '{') return false;
stk.pop();
}else{
return false;
}
}
}
return stk.empty();
}
};
标签:return,temp,有效,stk,括号,20,false,else,empty From: https://www.cnblogs.com/llllmz/p/18501445