Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f6a6027

Browse files
authored
Merge pull request neetcode-gh#1217 from UdayGarg/118-Pascals-Triangle
Create: 118-Pascals-Triangle.py
2 parents 76d362a + fda79c0 commit f6a6027

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

python/118-Pascals-Triangle.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class Solution:
2+
def generate(self, numRows: int) -> List[List[int]]:
3+
triangle = []
4+
for row_num in range(numRows):
5+
row = [None for _ in range(row_num + 1)]
6+
row[0], row[-1] = 1, 1
7+
for j in range(1, row_num):
8+
row[j] = triangle[row_num - 1][j-1] + triangle[row_num - 1][j]
9+
triangle.append(row)
10+
return triangle

0 commit comments

Comments
 (0)