백준 9012 괄호 - java


백준 9012 괄호 - java

import java.util.*; public class Main { public static void main (String args[]) { Scanner sc = new Scanner(System.in); Stack<Character> stack = new Stack<>(); int K = sc.nextInt(); sc.nextLine(); for (int i = 0; i < K; i++) { String input = sc.nextLine(); stack.clear(); int length = input.length(); boolean result = true; for (int j = 0; j < length; j++) { if (input.charAt(j) == ')') { if (stack.isEmpty()) { result = false; break; } else if (stack.peek() == '(') { stack.pop(); } } else if (input....



원문링크 : 백준 9012 괄호 - java