-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1804364
commit c4b6569
Showing
1 changed file
with
27 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |