We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent e206e6c commit 20ebbbfCopy full SHA for 20ebbbf
39. 杨辉三角.md
@@ -0,0 +1,14 @@
1
+***给定一个非负整数 numRows,生成「杨辉三角」的前 numRows 行。***
2
+
3
+
4
5
+```
6
+class Solution:
7
+ def generate(self, numRows: int) -> List[List[int]]:
8
+ #观察一下规律,发现当前一行只比上一行多了一个元素,最最关键的一点:本行元素等于上一行元素往后错一位再逐个相加
9
+ res = [[1]]
10
+ while len(res) < numRows:
11
+ newRow = [ a+b for a,b in zip(res[-1]+[0], [0]+res[-1])]
12
+ res.append(newRow)
13
+ return res
14
images/algo22.jpg
12 KB
0 commit comments