Created
March 1, 2015 20:50
-
-
Save dmnugent80/38630a49a2112bc8acee to your computer and use it in GitHub Desktop.
Pascal's Triangle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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