动态规划

https://github.com/labuladong/fucking-algorithm/blob/master/%E5%8A%A8%E6%80%81%E8%A7%84%E5%88%92%E7%B3%BB%E5%88%97/%E5%8A%A8%E6%80%81%E8%A7%84%E5%88%92%E8%AF%A6%E8%A7%A3%E8%BF%9B%E9%98%B6.md

1、120. 三角形最小路径和

class Solution:
    def minimumTotal(self, triangle: List[List[int]]) -> int:
        row = len(triangle)
        # data = [[float('inf')] * col for i in range(row)]
        # for trr in tr:


        for i in range(1, row):
            for j in range(0, len(triangle[i])):
                l = triangle[i-1][j] if 0 <= j < len(triangle[i-1]) else float('inf')
                r = triangle[i-1][j-1] if 0 <= j-1 < len(triangle[i-1]) else float('inf')
                triangle[i][j] = min(l, r) + \
                                 triangle[i][j]
        # print(triangle)
        return min(triangle[-1])

  

posted @ 2020-12-10 16:25  哈哈哈喽喽喽  阅读(85)  评论(0编辑  收藏  举报