Skip to content

Commit e69fc7b

Browse files
Create 118-Pascal-Triangle.py
1 parent 49a77d2 commit e69fc7b

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

python/118-Pascal-Triangle.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Solution:
2+
def generate(self, rowIndex) -> List[List[int]]:
3+
if rowIndex == 0:
4+
return [[1]]
5+
else:
6+
return self.getAllRow(rowIndex - 1)
7+
def getAllRow(self, rowIndex):
8+
if rowIndex == 0:
9+
return [[1]]
10+
ListPrec = self.getAllRow(rowIndex - 1)
11+
Len = len(ListPrec[-1])
12+
ListPrec.append([1])
13+
for i in range(0, Len - 1):
14+
ListPrec[-1].append(ListPrec[-2][i] + ListPrec[-2][i + 1])
15+
ListPrec[-1].append(1)
16+
return ListPrec

0 commit comments

Comments
 (0)