-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path118.py
More file actions
29 lines (25 loc) · 725 Bytes
/
118.py
File metadata and controls
29 lines (25 loc) · 725 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
from typing import List
class Solution:
def generate(self, numRows: int) -> List[List[int]]:
if numRows == 0:
return []
if numRows == 1:
return [[1]]
if numRows == 2:
return [[1], [1, 1]]
res = [[1], [1, 1]]
for i in range (2, numRows):
tmp = [0] + res[i - 1] + [0]
cur = [0] * (i + 1)
l, r = 0, i
while l <= r:
cur[l] = tmp[l] + tmp[l + 1]
cur[r] = tmp[r] + tmp[r + 1]
l += 1
r -= 1
res.append(cur)
return res
if __name__ == '__main__':
s = Solution()
for i in range(8):
print(s.generate(i))