A robot in the top-left corner of a grid filled with non-negative numbers moves only right or down. Return the minimum sum of a path to the bottom-right corner.
Example 1
minPathSum()
Input
grid =[[1,3,1],[1,5,1],[4,2,1]]
Output
7
Why
1 → 3 → 1 → 1 → 1
Example 2
minPathSum()
Input
grid =[[1,2,3],[4,5,6]]
Output
12
Constraints
1<= m, n <=2000<= grid[i][j]<=200
Topics
Dynamic ProgrammingMatrix
Implement minPathSum in the editor and return the answer — printing it is never graded.