LeetCode 1021:Remove Outermost Parentheses
作者:互联网
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; }
标签:Parentheses,1021,++,Outermost,sum,else,char,int,&& 来源: https://www.cnblogs.com/datsno1/p/10988889.html