File tree Expand file tree Collapse file tree 1 file changed +2
-7
lines changed
Expand file tree Collapse file tree 1 file changed +2
-7
lines changed Original file line number Diff line number Diff line change 66Python doctest can be run with the following command:
77python -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.
1010In Pascal's triangle, each number is the sum of the two numbers directly above it.
1111"""
1212
13-
1413class 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-
4743if __name__ == "__main__" :
4844 import doctest
49-
5045 doctest .testmod ()
You can’t perform that action at this time.
0 commit comments