File tree Expand file tree Collapse file tree 1 file changed +38
-0
lines changed
src/main/java/sgyj/inflearn/yeji/week4 Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change
1
+ package sgyj .inflearn .yeji .week4 ;
2
+
3
+ import java .util .Arrays ;
4
+ import java .util .Scanner ;
5
+ import java .util .Stack ;
6
+
7
+ public class Solution37 {
8
+ // 괄호문자제거
9
+ public static String solution (String input ){
10
+ StringBuilder answer = new StringBuilder ();
11
+ Stack <String > stack = new Stack ();
12
+ int i = 0 ;
13
+ int length = input .length ();
14
+ while (i <length ){
15
+ stack .push (String .valueOf (input .charAt (i )));
16
+ if (stack .peek ().equals (")" )){
17
+ stack .pop ();
18
+ while (!stack .peek ().equals ("(" )){
19
+ stack .pop ();
20
+ }
21
+ stack .pop ();
22
+ }
23
+ i ++;
24
+ }
25
+ while (!stack .isEmpty ()){
26
+ answer .append (stack .pop ());
27
+ }
28
+
29
+ return answer .reverse ().toString ();
30
+ }
31
+
32
+ public static void main (String [] args ){
33
+ Scanner sc = new Scanner ( System .in );
34
+ String input = sc .nextLine ();
35
+
36
+ System .out .println (solution (input ));
37
+ }
38
+ }
You can’t perform that action at this time.
0 commit comments