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.
1 parent acca70d commit 74bad1cCopy full SHA for 74bad1c
solutions/pascals-triangle.py
@@ -0,0 +1,26 @@
1
+"""
2
+- 118. Pascal's Triangle
3
+https://leetcode.com/problems/pascals-triangle/
4
5
+
6
+# Method 1
7
+class Solution:
8
+ def generate(self, numRows: int) -> List[List[int]]:
9
+ result = []
10
+ if numRows == 0:
11
+ return result
12
+ result.append([1])
13
+ if numRows == 1:
14
15
+ for i in range(2, numRows + 1):
16
+ temp = [0 for j in range(i)]
17
+ for j in range(len(temp)):
18
+ if j == 0:
19
+ temp[j] = result[-1][0]
20
+ elif j == len(temp) - 1:
21
+ temp[j] = result[-1][-1]
22
+ elif j != 0 and j != len(temp) - 1:
23
+ newNum = result[-1][j-1] + result[-1][j]
24
+ temp[j] = (newNum)
25
+ result.append(temp)
26
0 commit comments