118. 杨辉三角

题目链接:https://leetcode-cn.com/problems/pascals-triangle/

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
class Solution {
public List<List<Integer>> generate(int numRows) {
List<List<Integer>> res = new ArrayList<List<Integer>>();
for (int i = 0; i < numRows; i++) {
List<Integer> L = new ArrayList<Integer>();
for (int j = 0; j <= i; j++) {
if (j == 0 || i == j) {
L.add(1);
} else {
L.add(res.get(i - 1).get(j - 1) + res.get(i - 1).get(j));
}
}
res.add(L);
}
return res;
}
}

118. 杨辉三角
https://pisces34.github.io/2021/07/01/leetcode/yhtriangle1/
发布于
2021年7月1日
许可协议