118. Pascal's Triangle
My accepted Python solution to LeetCode problem 118, Pascal's Triangle, running in 0ms.
- Difficulty: Easy
- Python
- Runtime 0ms
- Memory 12.4MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
Python
Accepted on LeetCode — runtime 0ms, memory 12.4MB, accepted 2025-12-23.
class Solution(object):
def generate(self, numRows):
if numRows == 0:
return []
result = [[1]]
for i in range(1, numRows):
prev_row = result[-1]
new_row = [1]
for j in range(1, i):
new_row.append(prev_row[j-1] + prev_row[j])
new_row.append(1)
result.append(new_row)
return result