C语言
char * removeOuterParentheses(char * S){ int len = strlen(S); int j = 0; int sum = 0; for(int i = 0; i < len; i++) { if (S[i] == '(') { sum += 1; } else if (S[i] == ')') { sum -= 1; } if (S[i] == '(' && sum > 1) { S[j] = '('; j++; } else if (S[i] == ')' && sum > 0) { S[j] = ')'; j++; } else if (S[i] != '(' && S[i] != ')') { S[j] = S[i]; j++; } } S[j] = '\0'; return S; }