class Solution {
public:
/**
*
* @param s string字符串
* @return bool布尔型
*/
bool isValid(string s) {
// write code here
stack<char> ss;
bool a=false;
for(int i=0;i<s.length();i++){
if(s[i]=='['||s[i]=='{'||s[i]=='(')
ss.push(s[i]);
else if(ss.empty()) return false;
else{
if(s[i]==']'&&ss.top()=='[')
ss.pop();
else if(s[i]=='}'&&ss.top()=='{')
ss.pop();
else if(s[i]==')'&&ss.top()=='(')
ss.pop();
else
return false;
}
}
if(ss.empty()) return true;
else return false;
}
};
怎么定义栈不太熟,stack ss;