- Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathpascalTriangle.java
More file actions
Latest commit
22 lines (20 loc) · 648 Bytes
/
Copy pathpascalTriangle.java
File metadata and controls
22 lines (20 loc) · 648 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
publicclassSolution {
publicstaticArrayList<ArrayList<Integer>> generate(intnumRows) {
ArrayList<ArrayList<Integer>> result = newArrayList<ArrayList<Integer>>(numRows);;
if(numRows==0) {
returnresult;
}
for(inti=0;i<numRows;i++) {
ArrayList<Integer> tmp = newArrayList<Integer>(i+1);
tmp.add(1);
for (intj=1;j<i;j++) {
tmp.add(result.get(i-1).get(j-1) + result.get(i-1).get(j));
}
if(i>=1) {
tmp.add(1);
}
result.add(tmp);
}
returnresult;
}
}