public int solution(String s) {
Deque<Character> stack = new ArrayDeque<>();
for (char ch : s.toCharArray()) {
if (!stack.isEmpty() && stack.peek() == ch) {
stack.pop();
} else {
stack.push(ch);
}
}
return stack.isEmpty() ? 1 : 0;
}
출처:https://school.programmers.co.kr/learn/courses/30/lessons/12973