Skip to content

feat : 인프런 3주차 40 쇠막대기 #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions src/main/java/sgyj/inflearn/yeji/week4/Solution40.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package sgyj.inflearn.yeji.week4;

import java.util.Scanner;
import java.util.Stack;

public class Solution40 {

public static int solution(String[] input){
int answer = 0;
Stack<String> stack = new Stack();
int lt = Integer.MIN_VALUE;
int rt = Integer.MIN_VALUE;
for(int i = 0;i<input.length; i++){
if(input[i].equals("(")){
lt = i;
stack.push("(");
}else{
rt = i;
if(rt-lt==1){
stack.pop();
answer+=stack.size();
}else{
stack.pop();
answer+=1;
}
}
}
return answer;
}

public static void main(String[] args){
Scanner sc = new Scanner(System.in);
String input = sc.nextLine();
System.out.println(solution(input.split("")));
}
}