class Solution {
public String makeGood(String s) {
Stack<Character> stack = new Stack<>();
for (int i = 0; i < s.length(); ++i) {
char cur = s.charAt(i);
if (!stack.isEmpty() &&
Math.abs(stack.peek() - cur) == 32) {
stack.pop();
} else {
stack.push(cur);
}
}
StringBuilder sb = new StringBuilder();
while (!stack.isEmpty()) {
sb.insert(0, stack.pop());
}
return sb.toString();
}
}