外贸网站制作方案,合肥酒店团购网站建设,wordpress数据表开头,网站建设最简单的教程视频题目#xff1a; 给定一个非负整数 numRows#xff0c;生成「杨辉三角」的前 numRows 行。 在「杨辉三角」中#xff0c;每个数是它左上方和右上方的数的和。 来源#xff1a;力扣#xff08;LeetCode#xff09; 链接#xff1a;力扣#xff08;LeetCode#xff09;官… 题目 给定一个非负整数 numRows生成「杨辉三角」的前 numRows 行。 在「杨辉三角」中每个数是它左上方和右上方的数的和。 来源力扣LeetCode 链接力扣LeetCode官网 - 全球极客挚爱的技术成长平台 示例 示例 1 输入numRows 5 输出[0,1] 解释[[1],[1,1],[1,2,1],[1,3,3,1],[1,4,6,4,1]] 示例 2 输入numRows 1 输出[[1]] 解法 寻找规律 [1, 1] [0, 1] [1, 0] [1, 2, 1] [0, 1, 1] [1, 1, 0] [1, 3, 3, 1] [0, 1, 2, 1] [1, 2, 1, 0] [1, 4, 6, 4, 1] [0, 1, 3, 3, 1] [1, 3, 3, 1, 0] 所以第i行第i-1行左添0右添0得到。 代码 class Solution:def generate(self, numRows: int) - List[List[int]]:result []n [1]for _ in range(numRows):result.append(n)n [x y for x, y in zip([0] n, n [0])]return result