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