Problem
Each cell of an m × n grid holds a non-negative cost. Find a path from the top-left to the bottom-right cell, moving only right or down, that has the smallest sum of the cells it visits (including both corners). Return that sum.
Example 1
grid = [[1, 3, 1],
Example 2
[1, 5, 1],
Example 3
- Input
- [4, 2, 1]]
- Output
- 7
- Why
- 1 → 3 → 1 → 1 → 1
Example 4
grid = [[1, 2, 3],
Example 5
- Input
- [4, 5, 6]]
- Output
- 12
Constraints
1 <= m, n <= 200 where the grid is m × n0 <= grid[r][c] <= 200