Problem:
Given numRows, generate the first numRows of Pascal's triangle.
For example, given numRows = 5,
Return
[ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1] ]
Answer:
class Solution(object):
def generate(self, numRows):
"""
:type numRows: int
:rtype: List[List[int]]
"""
result = [[1 for j in range(i+1)] for i in range(numRows)]
for i in range(len(result)):
for j in range(len(result[i])):
if j == 0 or j == len(result[i])-1: continue
else: result[i][j] = result[i-1][j-1] + result[i-1][j]
return result