import java.util.Stack;
public class RemovePairChar {
public int solution(String s) {
Stack<Character> stack = new Stack<>();
for (char ele : s.toCharArray()) {
if (stack.isEmpty()) {
stack.push(ele);
continue;
}
if (stack.peek() == ele) {
stack.pop();
} else {
stack.push(ele);
}
}
return stack.isEmpty() ? 1 : 0;
}
public static void main(String[] args) {
RemovePairChar s = new RemovePairChar();
System.out.println(s.solution("baabaa"));
System.out.println(s.solution("cdcd"));
System.out.println(s.solution("caab"));
}
}