Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 984bf90

Browse files
python: add problem 118 and unittest
1 parent c45c52f commit 984bf90

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

Python/sln_101_200/solution_111_120.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,26 @@ def generate(self, numRows: int) -> List[List[int]]:
4545
results.append(row)
4646
return results
4747

48+
def getRow(self, rowIndex: int) -> List[int]:
49+
"""
50+
118
51+
:param rowIndex:
52+
:return:
53+
"""
54+
if rowIndex == 0:
55+
return [1]
56+
elif rowIndex == 1:
57+
return [1, 1]
58+
last_row = [1, 1]
59+
for row in range(2, rowIndex + 1):
60+
current_row = [1]
61+
for j in range(1, row):
62+
current_row.append(last_row[j - 1] + last_row[j])
63+
current_row.append(1)
64+
last_row = current_row
65+
return last_row
66+
67+
4868
def minimumTotal(self, triangle: List[List[int]]) -> int:
4969
"""
5070
120

0 commit comments

Comments
 (0)