思路:
自己写栈模拟了这个过程直接AC了。
const int N = 1e4+10;
class Solution {
public:
bool isValid(string s) {
char st[N];//栈
int tt=0,hh=-1;
for(int i=0;i<s.size();i++)
{
st[++hh]=s[i];
if(hh>=1&&hh>=tt)
{
if((st[hh]==')'&&st[hh-1]=='(')||(st[hh]=='}'&&st[hh-1]=='{')||(st[hh]==']'&&st[hh-1]=='['))//匹配的话
{
hh-=2;
}
}
}
if(hh==-1) return true;
return false;
}
};