119. Pascal's Triangle II
My accepted Python solution to LeetCode problem 119, Pascal's Triangle II, running in 3ms.
- Difficulty: Easy
- Python
- Runtime 3ms
- Memory 12.3MB
- 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 3ms, memory 12.3MB, accepted 2025-12-23.
class Solution(object):
def getRow(self, rowIndex):
row = [1]
for i in range(1, rowIndex + 1):
# Build row from right to left to avoid overwriting values
new_row = [1] * (i + 1)
for j in range(1, i):
new_row[j] = row[j-1] + row[j]
row = new_row
return row