import java.util.*;
class Solution {
public int solution(String s) {
int answer = -1;
Stack<Character> stack = new Stack<>();
for (char ch: s.toCharArray()) {
if (stack.isEmpty()) stack.push(ch);
else {
char tmp = stack.pop();
if (tmp != ch) {
stack.push(tmp);
stack.push(ch);
}
}
}
if (stack.size() == 0) answer = 1;
else answer = 0;
return answer;
}
}