-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpascalsTriangle2Solution.py
More file actions
25 lines (20 loc) · 1019 Bytes
/
pascalsTriangle2Solution.py
File metadata and controls
25 lines (20 loc) · 1019 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
class Solution:
def getRow(self, rowIndex: int) -> List[int]:
if (rowIndex == 0): return [1]
elif (rowIndex == 1): return [1,1]
else:
pascalTriangle = [[0 for x in range(0,rowIndex+2)] for x in range(0, rowIndex+2)]
for i in range(0,rowIndex+2):
for j in range(0,rowIndex+2):
pascalTriangle[0][j] = 1
pascalTriangle[i][0] = 1
for i in range(1, rowIndex+2):
for j in range(1,rowIndex-i+2):
#print(i,j,pascalTriangle[i-1][j] + pascalTriangle[i][j-1])
pascalTriangle[i][j] = pascalTriangle[i-1][j] + pascalTriangle[i][j-1]
answer = [0 for x in range(0,rowIndex+1)]
for i in range(0, rowIndex+1):
#print(i,rowIndex)
answer[i] = pascalTriangle[i][rowIndex]
rowIndex = rowIndex - 1
return answer