class Solution {
public:
bool isValid(string s) {
if(s.size()<||s.size()%!=)return false;
unordered_map<char,char>hashmap;
hashmap['(']=')';
hashmap['[']=']';
hashmap['{']='}';
if(s.size()==)return hashmap[s[]]==s[];
int i=;
int sum1=,sum2=;
int j;
while(i<s.size())
{
j=i-;
if(s[j]==s[])++sum1;
if(s[i]==hashmap[s[]]){
++sum2;
if(sum1==sum2){
if(i==s.size()-)return isValid(s.substr(,s.size()-));
if(i==)return isValid(s.substr(,s.size()-));
return isValid(s.substr(,i-))&&isValid(s.substr(i+,s.size()--i));
}
}
i=i+;
}
return false;
}
};