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

Method generate

src/com/blankj/easy/_0118/Solution.java:17–33  ·  view source on GitHub ↗
(int numRows)

Source from the content-addressed store, hash-verified

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();

Callers 1

mainMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected