118. Pascal's Triangle
Input: 5
Output:
[
[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]]
"""
res = []
for i in range(numRows):
temp = [0] * (i+1)
for j in range(i + 1):
if j == 0 or j == i:
temp[j] = 1
else:
temp[j] = res[i-1][j] + res[i-1][j-1]
res.append(temp)
return resLast updated
