public boolean isValid(String s) {
        if(s == null || s.isEmpty()) return true;
        Map<Character, Character> map = buildMap();
        Stack<Character> stack = new Stack<Character>();
        for(Character ch : s.toCharArray()){
            if(map.containsKey(ch)){
                stack.push(ch);
            }else{
                if(stack.isEmpty()) return false;
                Character top = stack.pop();
                if(!map.get(top).equals(ch)) return false;
            }
        }
        return stack.isEmpty();
    }