-
Notifications
You must be signed in to change notification settings - Fork 4
/
Solution.java
39 lines (35 loc) · 1012 Bytes
/
Solution.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package _118;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
* <pre>
* author: Blankj
* blog : http://blankj.com
* time : 2017/10/11
* desc :
* </pre>
*/
public class Solution {
public List<List<Integer>> generate(int numRows) {
if (numRows == 0) return Collections.emptyList();
List<List<Integer>> list = new ArrayList<>();
for (int i = 0; i < numRows; ++i) {
List<Integer> sub = new ArrayList<>();
for (int j = 0; j <= i; ++j) {
if (j == 0 || j == i) {
sub.add(1);
} else {
List<Integer> upSub = list.get(i - 1);
sub.add(upSub.get(j - 1) + upSub.get(j));
}
}
list.add(sub);
}
return list;
}
public static void main(String[] args) {
Solution solution = new Solution();
System.out.println(solution.generate(5));
}
}