bool checkArr(char * arr, int len, int* max) { if (NULL == arr || len == 0 || max == NULL) { return false; } int maxdepth = 0, deep = 0; for (int i = 0; i < len; i++) { char tmp = arr[i]; if (tmp == '(') { deep++; } else if (tmp == ')') { deep--; } maxdepth = deep > maxdepth ? deep : maxdepth; } *max = maxdepth; if (deep == 0) { return true; //deep长度是0,表示匹配; } return false; }