Skip to content

Commit 227bc29

Browse files
authored
Update pascals_triangle.py
1 parent 7309788 commit 227bc29

File tree

1 file changed

+2
-7
lines changed

1 file changed

+2
-7
lines changed

data_structures/arrays/pascals_triangle.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@
66
Python doctest can be run with the following command:
77
python -m doctest -v pascals_triangle.py
88
9-
Given a non-negative integer numRows, generate the first numRows of Pascal's triangle.
9+
Given a non-negative integer num_rows, generate the first num_rows of Pascal's triangle.
1010
In Pascal's triangle, each number is the sum of the two numbers directly above it.
1111
"""
1212

13-
1413
class Solution:
1514
def generate(self, num_rows: int) -> list[list[int]]:
1615
"""
@@ -35,16 +34,12 @@ def generate(self, num_rows: int) -> list[list[int]]:
3534
for i in range(num_rows):
3635
# Initialize the row with 1s
3736
row = [1] * (i + 1)
38-
3937
# Compute inner elements by summing elements from the previous row
4038
for j in range(1, i):
41-
row[j] = ans[i - 1][j - 1] + ans[i - 1][j]
42-
39+
row[j] = ans[i-1][j-1] + ans[i-1][j]
4340
ans.append(row)
4441
return ans
4542

46-
4743
if __name__ == "__main__":
4844
import doctest
49-
5045
doctest.testmod()

0 commit comments

Comments
 (0)