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