package tree;

import java.util.HashMap;
import java.util.Map;
import java.util.Stack;

/**
 * https://oj.leetcode.com/problems/valid-parentheses/
 * Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.
 * The brackets must close in the correct order, "()" and "()[]{}" are all valid but "(]" and "([)]" are not.
 */
public class ValidParentheses {
    public boolean isValid(String s) {
        int length = s == null ? 0 : s.length();
        if (length < 2) return false;
        Map<Character, Character> map = new HashMap<>();
        map.put(')', '(');
        map.put('}', '{');
        map.put(']', '[');
        Stack<Character> stack = new Stack<>();
        for (int i = 0; i < length; i++) {
            char tmp = s.charAt(i);
            if ('(' == tmp || '{' == tmp || '[' == tmp) {
                stack.push(tmp);
            } else {
                if (stack.isEmpty() || map.get(tmp) != stack.peek()) {
                    return false;
                } else {
                    stack.pop();
                }
            }
        }
        return stack.isEmpty();
    }
}

@@ -962,16 +962,28 @@
 get(tmp)
+.charValue()
  != stac
@@ -990,16 +990,28 @@
 k.peek()
+.charValue()
 ) %7B%0A    

convert Character to char