118. Pascal's Triangle@python
2021-06-15 08:06
标签:复杂度 .com end output == object nbsp generate inpu Given a non-negative integer numRows, generate the first numRows of Pascal‘s triangle. Example: 原题地址: Pascal‘s Triangle 难度: Easy 题意: 杨辉三角 时间复杂度: O(n) 空间复杂度: O(n) 118. Pascal's Triangle@python 标签:复杂度 .com end output == object nbsp generate inpu 原文地址:https://www.cnblogs.com/chimpan/p/9733018.htmlInput: 5
Output:
[
[1],
[1,1],
[1,2,1],
[1,3,3,1],
[1,4,6,4,1]
]
class Solution(object):
def generate(self, numRows):
"""
:type numRows: int
:rtype: List[List[int]]
"""
res = []
for i in range(numRows):
if i == 0:
row = [1]
else:
row = [1]
for j in range(1, i):
row.append(res[-1][j] + res[-1][j-1])
row.append(1)
res.append(row)
return res
文章标题:118. Pascal's Triangle@python
文章链接:http://soscw.com/index.php/essay/94107.html