Problem
Each entry in the rectangular grid costs is a nonnegative cost. A path starts in the upper-left cell, finishes in the lower-right cell, and advances one cell at a time to the right or downward.
Return the smallest total cost of any such path. Add the costs of every visited cell, including both endpoints.
Examples
Example 1
Input: costs = [[2,8,1],[3,1,1]]
Output: 7
Moving down, right, and right visits costs 2, 3, 1, and 1, for a total of 7. Every other permitted path costs more.
Example 2
Input: costs = [[5],[0],[4]]
Output: 9
There is only one column, so the path visits all three cells.
Constraints
-
The grid has between
1
and
200
rows and between
1
and
200
columns.
-
All rows have equal length.
-
0 <= costs[i][j] <= 200