/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param s string字符串
* @return bool布尔型
*/
#include <stdbool.h>
#include <stdlib.h>
bool isValid(char* s ) {
// write code here
int i = 0;
bool ret = false;
char* pStr = (char*)calloc(10001, sizeof(char));
long top = -1;
//printf("%d %d %d %d %d %d\n",'(',')','[',']','{','}');
memset(pStr, 0, 10001*sizeof(char));
for(i = 0; i < strlen(s); i++){
if(',' == s[i]){
continue;
}
//pop : 栈顶元素与当前字符括号配对 40-41 123-125
if((top >= 0)&&((pStr[top] == (s[i] - 1))||(pStr[top] == (s[i] - 2)))){
pStr[top] = 0;
top--;
}
else if(top <= 10000){
//push : 空栈或只有一个元素、栈顶元素与当前字符括号不配对
top++;
pStr[top] = s[i];
}
}
if(top == -1)
ret = true;
else
ret = false;
free(pStr);
return ret;
}