boolean solution(String s) {
return isCorrect(s);
}
private boolean isCorrect(String s) {
Stack<Character> stack = new Stack<>();
for (char c : s.toCharArray()) {
if (c == '(') {
stack.push(c);
} else if (!stack.isEmpty() && stack.peek() == '(') {
stack.pop();
} else {
stack.push(c);
}
}
return stack.isEmpty();
}
출처:https://school.programmers.co.kr/learn/courses/30/lessons/12909