classic stack problem.
class Solution {
public boolean isValid(String s) {
if (s == null || s.length() == 0) return false;
if (s.length() % 2 == 1) return false;
Stack<Character> stack = new Stack<>();
for (char c: s.toCharArray()) {
System.out.println(c);
if (c == '(') {
stack.push(')');
} else if (c == '[') {
stack.push(']');
} else if (c == '{') {
stack.push('}');
} else if (!stack.isEmpty() && ((c == ')' && stack.peek() == ')') || (c == ']' && stack.peek() == ']') || (c == '}' && stack.peek() == '}') )){
stack.pop();
} else {
return false;
}
}
return stack.isEmpty();
}
}