本来打算在leetcode上写道简单题练练手,就找了这题,看着也简单,就选它了。结果。。。。。
不提了
不过思路很简单,看看就懂了。
bool isValid(char * s){
char e,b[100];
int i=0;
char *stack=(char*)malloc(10000*sizeof(char));
int top=0;
int len=strlen(s);
if(len==1)return false;
while(s[i]!='\0'){
if(s[i]=='(' || s[i]=='[' || s[i]=='{'){
stack[top++]=s[i];
}
else{
top--;
if(top<0)return false;
if(s[i]==')' && stack[top]!='(')return false;
if(s[i]==']' && stack[top]!='[')return false;
if(s[i]=='}' && stack[top]!='{')return false;
}
i++;
}
if(top!=0)return false;
else return true;
}