import java.util.Stack;
public class NUM12909 {
public static void main() {
String s = "(())()";
System.out.println(solution(s));
}
public static boolean solution(String s) {
boolean answer = true;
Stack<Character> stack = new Stack<>();
for (int i = 0; i < s.length(); i++) {
if (s.charAt(i) == '(') {
stack.push('(');
} else {
if (stack.isEmpty()) answer = false;
else stack.pop();
}
}
if(answer) answer = stack.isEmpty();
return answer;
}
}
*다른 분들의 코드를 참고하여 작성했습니다