public boolean isValid (String s) {
        if(s.length()%2!=0){
            return false;
        }
        // write code here
        Map<Character, Character> pars = new HashMap<>();
        pars.put(')', '(');
        pars.put(']', '[');
        pars.put('}', '{');
        Stack<Character> stack = new Stack<>();
        for(int i=0; i<s.length(); i++){
            if(pars.containsKey(s.charAt(i))){
                if(stack.isEmpty() || stack.peek() != pars.get(s.charAt(i))){
                    return false;
                }
                stack.pop();
            }else{
                stack.push(s.charAt(i));
            }
        }
        return stack.isEmpty();
    }