public List<String> fullJustify(String[] words, int maxWidth) {
        List<String> res = new ArrayList<String>();
        if (words == null || maxWidth < 0) return res;

        int s = 0;
        int charsLen = 0;
        for (int e = 0; e < words.length; ++e)  {
            int span = charsLen + words[e].length() + (e - s); // length of words and spaces
            if (span <= maxWidth) charsLen += words[e].length(); // length of words
            else --e;

            if (span > maxWidth) {
                res.add(makeLine(s, e, words, maxWidth, charsLen, false));
                charsLen = 0;
                s = e + 1;
            } else if (e == words.length - 1) {
                res.add(makeLine(s, e, words, maxWidth, charsLen, true));
            }
        }
        return res;
    }