Skip to content

Commit 5843c7d

Browse files
committed
feat : 인프런 3주차 40 쇠막대기
1 parent 97d8d9a commit 5843c7d

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
}

0 commit comments

Comments
 (0)