Skip to content

Commit 43951f1

Browse files
authored
Merge pull request #1951 from laitooo/0118-pascals-triangle.dart
Create: 0118-Pascals-Triangle.dart
2 parents f5d4c97 + 7a722ee commit 43951f1

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

dart/0118-pascals-triangle.dart

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class Solution {
2+
List<List<int>> generate(int numRows) {
3+
if (numRows == 1) {
4+
return [[1]];
5+
}
6+
7+
List<List<int>> res = [[1], [1, 1]];
8+
for (int i=2; i<numRows; i++) {
9+
List<int> tmp = [];
10+
for (int j=0; j<i+1; j++) {
11+
if (j == 0 || j == i) {
12+
tmp.add(1);
13+
} else {
14+
tmp.add(res[i - 1][j - 1] + res[i - 1][j]);
15+
}
16+
}
17+
res.add(tmp);
18+
}
19+
return res;
20+
}
21+
}

0 commit comments

Comments
 (0)