MCPcopy Create free account
hub / github.com/Blankj/awesome-java-leetcode / Solution

Class Solution

src/com/blankj/easy/_0118/Solution.java:16–39  ·  view source on GitHub ↗

author: Blankj blog : http://blankj.com time : 2017/10/11 desc :

Source from the content-addressed store, hash-verified

14 * </pre>
15 */
16public class Solution {
17 public List<List<Integer>> generate(int numRows) {
18 if (numRows == 0) return Collections.emptyList();
19 List<List<Integer>> list = new ArrayList<>();
20 for (int i = 0; i < numRows; ++i) {
21 List<Integer> sub = new ArrayList<>();
22 for (int j = 0; j <= i; ++j) {
23 if (j == 0 || j == i) {
24 sub.add(1);
25 } else {
26 List<Integer> upSub = list.get(i - 1);
27 sub.add(upSub.get(j - 1) + upSub.get(j));
28 }
29 }
30 list.add(sub);
31 }
32 return list;
33 }
34
35 public static void main(String[] args) {
36 Solution solution = new Solution();
37 System.out.println(solution.generate(5));
38 }
39}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected