import java.util.Stack;
class Solution
{
public int solution(String s) {
Stack<Character> stack = new Stack<>();
char[] chars = s.toCharArray();
stack.push(chars[0]);
for (int i = 1; i < chars.length; i++) {
if (stack.isEmpty()) {
stack.push(chars[i]);
continue;
}
if (!stack.peek().equals(chars[i])) {
stack.push(chars[i]);
} else {
stack.pop();
}
}
return stack.isEmpty() ? 1 : 0;
}
}