leetcode PascalsTriangle
z
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import java.util.ArrayList;
import java.util.List;

public class PascalsTriangle {
public List<List<Integer>> generate(int numRows) {
List<Integer> t = new ArrayList<>();
t.add(1);
List<List<Integer>> ans = new ArrayList<>();
ans.add(t);
for (int i=1; i<numRows; i++) {
List<Integer> temp = new ArrayList<>();
for (int j=0; j<=i; j++) {
if (j==0 || j == i) {
temp.add(1);
}
else {
temp.add(ans.get(ans.size()-1).get(j) + ans.get(ans.size()-1).get(j-1));
}
}
ans.add(temp);
}
return ans;
}
}