forked from yubinbai/leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution.java
More file actions
29 lines (29 loc) · 828 Bytes
/
Solution.java
File metadata and controls
29 lines (29 loc) · 828 Bytes
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
import java.util.*;
public class Solution {
public List<List<Integer>> generate(int numRows) {
List<List<Integer>> ret = new ArrayList<List<Integer>>();
List<Integer> curr = new ArrayList<Integer>();
curr.add(1);
ret.add(curr);
if (numRows == 1) {
return ret;
}
for (int i = 1; i < numRows; i++) {
List<Integer> next = new ArrayList<Integer>();
next.add(1);
for (int j = 1; j < curr.size(); j++) {
next.add(curr.get(j - 1) + curr.get(j));
}
next.add(1);
ret.add(next);
curr = next;
}
return ret;
}
public static void main(String[] args) {
Solution s = new Solution();
for (List<Integer> a : s.generate(10)) {
System.out.println(a);
}
}
}