MCPcopy Create free account
hub / github.com/codemistic/Data-Structures-and-Algorithms / minPathSum

Function minPathSum

Python/minimum_path_sum.py:2–17  ·  view source on GitHub ↗
(self, grid: List[List[int]])

Source from the content-addressed store, hash-verified

1//LEETCODE- 64. Minimum Path Sum
2 def minPathSum(self, grid: List[List[int]]) -> int:
3 nR = len(grid)
4 nC = len(grid[0])
5 adj = [(1, 0), (0, 1)]
6
7 @cache
8 def dfs(r, c):
9 if r == nR - 1 and c == nC - 1:
10 return grid[r][c]
11 paths = []
12 for a, b in adj:
13 r2, c2 = r + a, c + b
14 if 0 <= r2 < nR and 0 <= c2 < nC:
15 paths.append(dfs(r2, c2))
16 return grid[r][c] + min(paths)
17 return dfs(0, 0)

Callers

nothing calls this directly

Calls 1

dfsFunction · 0.70

Tested by

no test coverage detected