forked from luliyucoordinate/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0120.py
More file actions
23 lines (20 loc) · 632 Bytes
/
0120.py
File metadata and controls
23 lines (20 loc) · 632 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
class Solution:
def minimumTotal(self, triangle):
"""
:type triangle: List[List[int]]
:rtype: int
"""
if not triangle:
return 0
for row in range(len(triangle) - 1, 0, -1):
for col, _ in enumerate(triangle[row - 1]):
triangle[row - 1][col] += min(triangle[row][col] ,triangle[row][col + 1])
return triangle[0][0]
if __name__ == '__main__':
triangle = [
[2],
[3,4],
[6,5,7],
[4,1,8,3]
]
print(Solution().minimumTotal(triangle))