Codementor Events

LeetCode - Pascal Triangle

Published Aug 23, 2018

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]
]
Solution:
class Solution(object):
def generate(self, numRows):
lists = []
for i in range(numRows):
lists.append([1]*(i+1))
if i>1 :
for j in range(1,i):
lists[i][j]=lists[i-1][j-1]+lists[i-1][j]
return list
"""
:type numRows: int
:rtype: List[List[int]]
"""

Discover and read more posts from Kuldeep Luvani
get started
post commentsBe the first to share your opinion
Show more replies