public static int solution(final String s) {

        // If it's empty then it's nested properly.
        if (s.length() == 0) {
            return 1;
        }

        // If not even then it can't be nested properly.
        if (s.length() % 2 != 0) {
            return 0;
        }

        char c;
        Stack<Character> parentheses = new Stack<Character>();
        for (int i = 0; i < s.length(); i++) {
            c = s.charAt(i);
            if (c == '(' || c == '{' || c == '[') {
                parentheses.add(c);
            } else { // Closing bracket
                if (parentheses.empty() || !match(c, parentheses.pop())) {
                    return 0;
                }
            }
        }

        if (parentheses.empty()) {
            return 1;
        } else {
            return 0;
        }

    }