public static boolean isVaild(String s) {
        boolean flag = true;
        LinkedList<Character> stack = new LinkedList<Character>();

        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i) == '(' || s.charAt(i) == '[' || s.charAt(i) == '{') {
                stack.addFirst(s.charAt(i));
            } else {
                if (stack.isEmpty()) {
                    flag = false;
                    break;
                } else {
                    char ch = stack.removeFirst();
                    if (!checkMatching(ch, s.charAt(i))) {
                        flag = false;
                        break;
                    }
                }
            }
        }

        if (!stack.isEmpty()) {
            flag = false;
        }

        return flag;
    }