-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path119. Pascal's Triangle II.py
More file actions
42 lines (35 loc) · 924 Bytes
/
119. Pascal's Triangle II.py
File metadata and controls
42 lines (35 loc) · 924 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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
class Solution(object):
def getRow(self, rowIndex):
"""
:type rowIndex: int
:rtype: List[int]
"""
row = [1]
for _ in range(rowIndex):
row = [x + y for x, y in zip([0]+row, row+[0])]
print(row)
return row
a = Solution()
print(a.getRow(3))
class Solution(object):
def getRow(self, rowIndex):
"""
:type rowIndex: int
:rtype: List[int]
"""
return self.generate(rowIndex+1)[rowIndex]
#LC 118
def generate(self, numRows):
"""
:type numRows: int
:rtype: List[List[int]]
"""
res =[]
for i in range(numRows):
res.append([1])
for j in range(1,i+1):
if j == i:
res[i].append(1)
else:
res[i].append(res[i-1][j-1] +res[i-1][j])
return res