Skip to content

Commit

Permalink
Algorithm-day08
Browse files Browse the repository at this point in the history
  • Loading branch information
respect98 committed Nov 30, 2022
1 parent 6c517e4 commit 72b365e
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions Algorithm/day08/Q26_Bracket.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package day08;

import java.util.*;

public class Q26_Bracket {

public String solution(String str) {
String answer = "YES";
Stack<Character> stack = new Stack<>();
for (char x : str.toCharArray()) {
if (x == '(')
stack.push(x);
else {
if (stack.isEmpty())
return "No";
stack.pop();
}
}
if(!stack.isEmpty()) return "NO";
return answer;
}


public static void main(String[] args) {
System.out.println("괄호를 입력하세요: ");
Scanner sc = new Scanner(System.in);
String str = sc.next();
Q26_Bracket app = new Q26_Bracket();
System.out.println(app.solution(str));
}

}

0 comments on commit 72b365e

Please sign in to comment.