Skip to content

Commit 2be9ca3

Browse files
committed
Sync LeetCode submission Runtime - 0 ms (100.00%), Memory - 17.6 MB (55.36%)
1 parent 540e510 commit 2be9ca3

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

0118-pascals-triangle/solution.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
1-
# Approach 1 - Dynamic Programming (Iterative)
1+
# Appraoch 1: Dynamic Programming
2+
3+
# Time: O(numRows ^ 2)
4+
# Space: O(1)
25

36
class Solution:
47
def generate(self, numRows: int) -> List[List[int]]:
58
triangle = []
6-
9+
710
for row_num in range(numRows):
811
row = [None for _ in range(row_num + 1)]
9-
12+
# The first and last row elements are always 1.
1013
row[0], row[-1] = 1, 1
11-
14+
15+
# Each triangle element is equal to the sum of the elements
16+
# above-and-to-the-left and above-and-to-the-right.
1217
for j in range(1, len(row) - 1):
1318
row[j] = triangle[row_num - 1][j - 1] + triangle[row_num - 1][j]
14-
19+
1520
triangle.append(row)
16-
21+
1722
return triangle
1823

0 commit comments

Comments
 (0)