/***
 * Given numRows, generate the first numRows of Pascal's triangle.
 *
 * For example, given numRows = 5,
 * Return
 *
 * [
 *      [1],
 *     [1,1],
 *    [1,2,1],
 *   [1,3,3,1],
 *  [1,4,6,4,1]
 * ]
 */
import java.util.ArrayList;

public class Solution {
    public ArrayList<ArrayList<Integer>> generate(int numRows) {
        if (numRows == 0)
            return new ArrayList<ArrayList<Integer>>();
        ArrayList<ArrayList<Integer>> ret = new ArrayList<ArrayList<Integer>>();
        ArrayList<Integer> level = new ArrayList<Integer>();
        level.add(1);
        while (numRows-- != 0) {
            ArrayList<Integer> newlevel = new ArrayList<Integer>(level);
            ret.add(newlevel);
            level = generateNext(level);
        }
        return ret;
    }

    private ArrayList<Integer> generateNext(ArrayList<Integer> level) {
        ArrayList<Integer> newlevel = new ArrayList<Integer>();
        newlevel.add(1);
        for (int i = 0; i < level.size() - 1; i++){
            newlevel.add(level.get(i) + level.get(i + 1));
        }
        newlevel.add(1);
        return newlevel;
    }
}

@@ -257,16 +257,54 @@
 ution %7B%0A
+    // Solution 1: T: O(n%5E2), S: O(n)%0A
     publ
@@ -372,49 +372,8 @@
     
-if (numRows == 0)%0A            return new 
 Arra
@@ -393,35 +393,34 @@
 st%3CInteger%3E%3E
-();%0A       
+ ret = new
  ArrayList%3CA
@@ -441,50 +441,60 @@
 er%3E%3E
- ret = new ArrayList%3CArrayList%3CInteger%3E%3E()
+();%0A        if (numRows == 0)%0A            return ret
 ;%0A  

add PascalsTriangle.java