Skip to content

Commit

Permalink
1021
Browse files Browse the repository at this point in the history
  • Loading branch information
isinsuarici committed Jan 8, 2022
1 parent 1804364 commit c4b6569
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions E_1021_RemoveOutermostParentheses.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
class Solution {
public String removeOuterParentheses(String S) {
// 3 ms
int L = 0, R = 0;
StringBuilder sonuc = new StringBuilder();
StringBuilder temp= new StringBuilder();
for (int i = 0; i < S.length(); i++) {
if (S.charAt(i) == '(')
L++;
else if (S.charAt(i) == ')')
R++;
if (L == R) {
for(int x=i-L-R+1; x<i+1;x++){
temp.append(S.charAt(x));
}
for (int j = 1; j < L+R-1; j++) {
sonuc.append(temp.charAt(j));
}
L=0; R=0;
temp = new StringBuilder();

}
}

return sonuc.toString();
}
}

0 comments on commit c4b6569

Please sign in to comment.