File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed
src/main/java/sgyj/inflearn/yeji/week4 Expand file tree Collapse file tree 1 file changed +36
-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 Solution40 {
7
+
8
+ public static int solution (String [] input ){
9
+ int answer = 0 ;
10
+ Stack <String > stack = new Stack ();
11
+ int lt = Integer .MIN_VALUE ;
12
+ int rt = Integer .MIN_VALUE ;
13
+ for (int i = 0 ;i <input .length ; i ++){
14
+ if (input [i ].equals ("(" )){
15
+ lt = i ;
16
+ stack .push ("(" );
17
+ }else {
18
+ rt = i ;
19
+ if (rt -lt ==1 ){
20
+ stack .pop ();
21
+ answer +=stack .size ();
22
+ }else {
23
+ stack .pop ();
24
+ answer +=1 ;
25
+ }
26
+ }
27
+ }
28
+ return answer ;
29
+ }
30
+
31
+ public static void main (String [] args ){
32
+ Scanner sc = new Scanner (System .in );
33
+ String input = sc .nextLine ();
34
+ System .out .println (solution (input .split ("" )));
35
+ }
36
+ }
You can’t perform that action at this time.
0 commit comments