Skip to content

Commit 241e121

Browse files
118. Pascal's Triangle (java)
1 parent db42d21 commit 241e121

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)