118. Pascal's Triangle
All prompts are owned by LeetCode. To view the prompt, click the title link above.
First completed : May 22, 2024
Last updated : July 11, 2024
Related Topics : Array, Dynamic Programming
Acceptance Rate : 75.97 %
class Solution:
def generate(self, numRows: int) -> List[List[int]]:
self.output = []
for i in range(0, numRows) :
self.output.append([1])
if (numRows == 1) :
return self.output
self.output[1].append(1)
if (numRows == 2) :
return self.output
# program starts row 3
for i in range(2, numRows) :
for j in range(1, (i + 2) // 2) :
self.output[i].append(self.output[i-1][j] + self.output[i-1][j - 1])
self.output[i].extend(reversed(self.output[i][0:((i + 1) // 2)]))
return self.output