Skip to content

Instantly share code, notes, and snippets.

@dmnugent80
Created March 1, 2015 20:50
Show Gist options
  • Save dmnugent80/38630a49a2112bc8acee to your computer and use it in GitHub Desktop.
Save dmnugent80/38630a49a2112bc8acee to your computer and use it in GitHub Desktop.
Pascal's Triangle
public class Solution {
public List<List<Integer>> generate(int numRows) {
List<List<Integer>> allRows = new ArrayList<List<Integer>>();
ArrayList<Integer> row = new ArrayList<Integer>();
for (int i = 0; i < numRows; i++){
row.add(0, 1);
for (int j = 1; j < row.size()-1; j++){
row.set(j, row.get(j) + row.get(j+1));
}
allRows.add(new ArrayList<Integer>(row));
}
return allRows;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment