public NestedInteger deserialize(String s) {
        Stack<NestedInteger> stack = new Stack();

        NestedInteger current = null;
        StringBuffer subInteger = new StringBuffer();
        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i) == '[') {
                if (current != null) {
                    stack.push(current);
                }
                current = new NestedInteger();
                subInteger = new StringBuffer();
            } else if (s.charAt(i) == ']') {
                if (subInteger.length() > 0) {
                    current.add(new NestedInteger(Integer.parseInt(subInteger.toString())));
                    subInteger = new StringBuffer();
                }
                if (!stack.isEmpty()) {
                    NestedInteger top = stack.pop();
                    top.add(current);
                    current = top;
                }
            } else if (s.charAt(i) == ',') {
                if (subInteger.length() > 0) {
                    current.add(new NestedInteger(Integer.parseInt(subInteger.toString())));
                }
                subInteger = new StringBuffer();
            } else {
                subInteger.append(s.charAt(i));
            }
        }
        if (subInteger.length() > 0) {
            return new NestedInteger(Integer.parseInt(subInteger.toString()));
        }
        return current;
    }
Date 10/10/2016
@author Tushar Roy

Given a nested list of integers represented as a string, implement a parser to deserialize it.
Each element is either an integer, or a list -- whose elements may also be integers or other lists.

https://leetcode.com/problems/mini-parser/
src/com/interview/misc/IntegerListParser.java