118. 杨辉三角
小于 1 分钟
118. 杨辉三角简单
class Solution:
def generate(self, numRows: int) -> List[List[int]]:
res = []
for i in range(numRows):
m = []
for j in range(i + 1):
if j == 0 or j == i:
m.append(1)
else:
m.append(res[i - 1][j - 1] + res[i - 1][j])
res.append(m)
return res
Powered by Waline v2.15.5