class Solution {
public:
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param s string字符串
* @return bool布尔型
*/
bool isValid(string s) {
// write code here
stack<char> charstack;
for(int i=0; i<s.size(); i++){
if(!charstack.empty()){
if(s[i] == ']' && charstack.top() == '['||\
s[i] == ')' && charstack.top() == '(' ||\
s[i] == '}' && charstack.top() == '{'){
charstack.pop();
}
else{
charstack.push(s[i]);
}
}else if(charstack.empty()){
charstack.push(s[i]);
}
}
if(charstack.empty()){
return true;
}else{
return false;
}
}
};