We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent a71618f commit fbf3da5Copy full SHA for fbf3da5
1 file changed
dynamic_programming/triangle.py
@@ -0,0 +1,11 @@
1
+class Solution:
2
+ def minimumTotal(self, triangle: List[List[int]]) -> int:
3
+ for row in range(1, len(triangle)):
4
+ for col in range(row + 1):
5
+ smallest_above = math.inf
6
+ if col > 0:
7
+ smallest_above = triangle[row - 1][col - 1]
8
+ if col < row:
9
+ smallest_above = min(smallest_above, triangle[row - 1][col])
10
+ triangle[row][col] += smallest_above
11
+ return min(triangle[-1])
0 commit comments