-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution_118.java
More file actions
40 lines (35 loc) · 891 Bytes
/
Solution_118.java
File metadata and controls
40 lines (35 loc) · 891 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
30
31
32
33
34
35
36
37
38
39
40
package com.hilbert25.leetcode;
import java.util.ArrayList;
import java.util.List;
/**
* @author : hilbert25
* @version 创建时间:2017年5月12日 下午11:57:01 LeetCode com.hilbert25.leetcode
* Solution_118
*/
public class Solution_118 {
public static void main(String[] args) {
// TODO Auto-generated method stub
}
/**
* @param numRows
* @return
*/
public List<List<Integer>> generate(int numRows) {
List<List<Integer>> res = new ArrayList<List<Integer>>(numRows);
if (numRows == 0)
return res;
List<Integer> temp = new ArrayList<Integer>(1);
temp.add(1);
res.add(temp);
for (int i = 1; i < numRows; i++) {
List<Integer> list = new ArrayList<Integer>(i + 1);
list.add(1);
for (int j = 1; j < i; j++) {
list.add(res.get(i - 1).get(j) + res.get(i - 1).get(j - 1));
}
list.add(1);
res.add(list);
}
return res;
}
}