class Solution {
public:
bool isValid(string s) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
stack<char> mystack;
int count = s.length();
for(int i = 0;i < count;i++)
{
if(s[i]=='('||s[i]=='{'||s[i]=='[')
{
mystack.push(s[i]);
}
else
{
if(mystack.empty())
return false;
switch(s[i])
{
case '}':if(mystack.top()!='{')
return false;
break;
case ']':if(mystack.top()!='[')
return false;
break;
case ')':if(mystack.top()!='(')
return false;
break;
}
mystack.pop();
}
}
return mystack.empty();
}
};