class Solution { public String removeOuterParentheses(String S) { int outer = 0; int inner = 0; char[] intput = S.toCharArray(); char[] output = new char[intput.length]; int i = 0; for (char c: intput) { if (outer != 0) { if (inner == 0) { if (‘)‘ == c) { outer += 1; } else { inner -= 1; output[i] = c; i += 1; } } else { if (‘(‘ == c) { inner -= 1; output[i] = c; i += 1; } else { inner += 1; output[i] = c; i += 1; } } } else { outer -= 1; } } return new String(output).substring(0,i); } }
原文地址:https://www.cnblogs.com/stone94/p/10927031.html
时间: 2024-10-31 22:24:07