Description
Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right, which minimizes the sum of all numbers along its path. You can only move either down or right at any point in time.
Examples
Input:
grid = [[1,3,1],[1,5,1],[4,2,1]]Output:
7Explanation:
Path 1→3→1→1→1 minimizes the sum.
Input:
grid = [[1,2,3],[4,5,6]]Output:
12Explanation:
Path 1→2→3→6 minimizes the sum.
Input:
grid = [[5,1,2,4],[2,3,1,1],[1,2,4,2],[3,1,1,0]]Output:
8Explanation:
The minimum cost path through the grid sums to 8 by choosing the sequence of cells with the lowest cumulative cost from top-left to bottom-right.
Constraints
- •
m == grid.length - •
n == grid[i].length - •
1 ≤ m, n ≤ 200 - •
0 ≤ grid[i][j] ≤ 100