MCPcopy Create free account
hub / github.com/HuberTRoy/leetCode / minPathSum

Method minPathSum

Array/MinimumPathSum.py:45–62  ·  view source on GitHub ↗

:type grid: List[List[int]] :rtype: int

(self, grid)

Source from the content-addressed store, hash-verified

43 return (up, left)
44
45 def minPathSum(self, grid):
46 """
47 :type grid: List[List[int]]
48 :rtype: int
49 """
50
51 for i in range(len(grid)):
52 for j in range(len(grid[0])):
53 xy = self.get_up_left(j, i)
54 up = grid[xy[0][1]][xy[0][0]] if xy[0] else float('inf')
55 left = grid[xy[1][1]][xy[1][0]] if xy[1] else float('inf')
56
57 if up == float('inf') and left == float('inf'):
58 continue
59 grid[i][j] = grid[i][j] + min(up, left)
60
61
62 return grid[-1][-1]

Callers

nothing calls this directly

Calls 1

get_up_leftMethod · 0.95

Tested by

no test coverage detected