← 返回 amazon 的题目列表Minimum Path Sum in a Grid
类型:online_judge
Given a grid consisting of 0s, 1s, and 2s, where each element represents a number on it, start from the top-left corner and move to the bottom-right corner with the restriction of moving only right or down. Return the minimum path sum of the numbers encountered on the path.
Input:
A 2D list representing a grid where each element is 0, 1, or 2.
Output:
An integer representing the minimum sum of numbers from top-left to bottom-right.
Example:
Input:
[[0, 1, 2],
[1, 2, 0],
[2, 0, 1]]
Output: 4
Example
Input
[[0, 1, 2], [1, 2, 0], [2, 0, 1]]