20. Valid Parentheses

class Solution {
    public boolean isValid(String s) {
        if (s == null || s.length() == 0) return false;

        Stack<Character> stack = new Stack<>();
        for (char c : s.toCharArray()){
            if (c == '('){
                stack.push(')');
            }
            else if (c == '['){
                stack.push(']');
            }
            else if (c == '{'){
                stack.push('}');
            }
            else if (stack.size() == 0 || c != stack.pop()){
                return false;
            }
        }

        return stack.size() == 0;
    }
}

results for ""

    No results matching ""