Skip to content

Commit

Permalink
Create 118-Pascal-Triangle.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitali-Matteo authored Aug 23, 2022
1 parent 49a77d2 commit e69fc7b
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions python/118-Pascal-Triangle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class Solution:
def generate(self, rowIndex) -> List[List[int]]:
if rowIndex == 0:
return [[1]]
else:
return self.getAllRow(rowIndex - 1)
def getAllRow(self, rowIndex):
if rowIndex == 0:
return [[1]]
ListPrec = self.getAllRow(rowIndex - 1)
Len = len(ListPrec[-1])
ListPrec.append([1])
for i in range(0, Len - 1):
ListPrec[-1].append(ListPrec[-2][i] + ListPrec[-2][i + 1])
ListPrec[-1].append(1)
return ListPrec

0 comments on commit e69fc7b

Please sign in to comment.