64. Minimum Path Sum
# Medium
Is very similar to #62.
1. minPath represents minimum path instead of possible paths.
2. minPath initilizes each edge element: minPath[x][y]=grid[x][y].
Solution:
Initilize
minPath[0][0] = grid[0][0]
Initilize the edge elements of minPath:
minPath[x][y] = grid[x][y]+grid[0][0]
Initilize other elements of minPath:
minPath[x][y] = min(minPath[x-1][y], minPath[x][y-1]) + grid[x][y]
Last updated
Was this helpful?