Minimum Path Sum
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.
Note: You can only move either down or right at any point in time.
Example 1:
Input: grid = [[1,3,1],[1,5,1],[4,2,1]]
Output: 7
Explanation: Because the path 1 → 3 → 1 → 1 → 1 minimizes the sum.
Example 2:
Input: grid = [[1,2,3],[4,5,6]]
Output: 12
Constraints:
- m == grid.length
- n == grid[i].length
- 1 <= m, n <= 200
- 0 <= grid[i][j] <= 100
最小和路径
给定一个充满非负数的m x n网格,找出一条从左上角到右下角的路径,使其沿途的所有数字之和最小。
注意:在任何时候,你只能向左或者向右移动
例子1:
输入: grid = [[1,3,1],[1,5,1],[4,2,1]]
输出: 7
解释: 因为1-3-1-1-1-1的和最小
例子2:
输入: grid = [[1,2,3],[4,5,6]]
输出: 12
限制
- m == grid.长度
- n == grid[i].长度
- 1 <= m, n <= 200
- 0 <= grid[i][j] <= 100