Skip to content

Commit

Permalink
Create: 0118-Pascals-Triangle.dart
Browse files Browse the repository at this point in the history
  • Loading branch information
laitooo committed Jan 8, 2023
1 parent ff32745 commit 7a722ee
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions dart/0118-pascals-triangle.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class Solution {
List<List<int>> generate(int numRows) {
if (numRows == 1) {
return [[1]];
}

List<List<int>> res = [[1], [1, 1]];
for (int i=2; i<numRows; i++) {
List<int> tmp = [];
for (int j=0; j<i+1; j++) {
if (j == 0 || j == i) {
tmp.add(1);
} else {
tmp.add(res[i - 1][j - 1] + res[i - 1][j]);
}
}
res.add(tmp);
}
return res;
}
}

0 comments on commit 7a722ee

Please sign in to comment.