-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathpascal.py
More file actions
27 lines (24 loc) · 687 Bytes
/
pascal.py
File metadata and controls
27 lines (24 loc) · 687 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
class Solution(object):
def generate(self, numRows):
"""
:type numRows: int
:rtype: List[List[int]]
"""
# Hard code the first 2 rows as a memo
if numRows == 0:
return []
else:
memo = [[1]]
# Logic:
# * Leave out 0 and len()-1
# * for i add prev(i-1) + prev(i)
while len(memo) < numRows:
i = 1
prev = memo[-1]
memo.append([1])
while i < len(memo)-1:
value = prev[i-1]+prev[i]
memo[-1].append(value)
i += 1
memo[-1].append(1)
return memo