We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent db42d21 commit 241e121Copy full SHA for 241e121
solution/0118.Pascal's Triangle/Solution.java
@@ -0,0 +1,17 @@
1
+class Solution {
2
+ public List<List<Integer>> generate(int numRows) {
3
+ List<List<Integer>> re = new ArrayList<>();
4
+ if (numRows == 0) return re;
5
+ re.add(Collections.singletonList(1));
6
+ for (int i = 1; i < numRows; i++) {
7
+ List<Integer> list = new ArrayList<>();
8
+ re.add(list);
9
+ for (int j = 0; j < i + 1; j++) {
10
+ int l = j - 1 < 0 ? 0 : re.get(i - 1).get(j - 1);
11
+ int r = j > i - 1 ? 0 : re.get(i - 1).get(j);
12
+ list.add(l + r);
13
+ }
14
15
+ return re;
16
17
+}
0 commit comments