Java easy to understand solution.


  • 0
    C
    public List<List<Integer>> generate(int numRows) {
        List<List<Integer>> ret = new ArrayList<List<Integer>>();
        List<Integer> row = new ArrayList<Integer>();
        for (int i=0; i<numRows; i++) {
            row.add(1);
            for (int j=1; j<i; j++)
                row.set(j, ret.get(i-1).get(j-1)+ret.get(i-1).get(j));
            ret.add(new ArrayList<Integer>(row));
        }
        return ret;
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.