标签:复杂度 .com end output == object nbsp generate inpu
Given a non-negative integer numRows, generate the first numRows of Pascal‘s triangle.
Example:
Input: 5 Output: [ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1] ]
原题地址: Pascal‘s Triangle
难度: Easy
题意: 杨辉三角
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
时间复杂度: O(n)
空间复杂度: O(n)
标签:复杂度 .com end output == object nbsp generate inpu
原文地址:https://www.cnblogs.com/chimpan/p/9733018.html