1021. 删除最外层的括号
代码:
class Solution {
public String removeOuterParentheses(String S) {
StringBuffer str = new StringBuffer();
int countL = 0, countR = 0;
for (int i = 0; i < S.length(); i++)
{
if (S.charAt(i) == '(') countL++;
else if (S.charAt(i) == ')') countR++;
if (countL == countR) {
countL = 0;
countR = 0;
}
else if (countL != 1) str.append(S.charAt(i));
}
return str.toString();
}
}