We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents ff4e69c + 3c6ea49 commit f6e8544Copy full SHA for f6e8544
solution/0100-0199/0118.Pascal's Triangle/Solution.py
@@ -0,0 +1,18 @@
1
+class Solution:
2
+ def generate(self, numRows: int) -> List[List[int]]:
3
+ res = [[1], [1, 1]]
4
+ if numRows == 0:
5
+ return []
6
+ elif numRows == 1:
7
+ return [res[0]]
8
+
9
+ # from the 3. row on
10
+ for i in range(2, numRows):
11
+ counter = 1
12
+ temp = [1, 1]
13
+ # should add len(res[i - 1]) - 1 elements in to temp
14
+ for j in range(len(res[i - 1]) - 1):
15
+ temp.insert(counter, res[i - 1][j] + res[i - 1][j + 1])
16
+ counter += 1
17
+ res.append(temp)
18
+ return res
0 commit comments