Участник:Ковальков Антон М05-903б/Minimum Path Sum

Материал из DISCOPAL
Перейти к: навигация, поиск

https://leetcode.com/problems/minimum-path-sum

Python3

class Solution:
    def minPathSum(self, grid: List[List[int]]) -> int:
        for i in range(len(grid)):
            for j in range(len(grid[0])):
                if i == 0 and j == 0:
                    continue
                m = float('inf')
                if i > 0:
                    m = grid[i-1][j]
                if j > 0 and grid[i][j-1] < m:
                    m = grid[i][j-1]
                grid[i][j] += m
        return grid[-1][-1]