给定一个非负整数 numRows,生成杨辉三角的前 numRows 行。
示例:
输入: 5
输出:
[
[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]] """ result = [] for i in range(numRows): temp = [0] * (i + 1) temp[0],temp[-1] = 1,1 for j in range(1, len(temp) - 1): temp[j] = result[i - 1][j - 1] + result[i - 1][j] result.append(temp) return result