# 最小路径和

<p>给定一个包含非负整数的 <code><em>m</em> x <em>n</em></code> 网格 <code>grid</code> ，请找出一条从左上角到右下角的路径，使得路径上的数字总和为最小。</p><p><strong>说明：</strong>每次只能向下或者向右移动一步。</p><p> </p><p><strong>示例 1：</strong></p><img alt="" src="https://img-service.csdnimg.cn/img_convert/0c6d9496445c66b255a406ba2f9a3eb9.jpeg" style="width: 242px; height: 242px;" /><pre><strong>输入：</strong>grid = [[1,3,1],[1,5,1],[4,2,1]]<strong><br />输出：</strong>7<strong><br />解释：</strong>因为路径 1→3→1→1→1 的总和最小。</pre><p><strong>示例 2：</strong></p><pre><strong>输入：</strong>grid = [[1,2,3],[4,5,6]]<strong><br />输出：</strong>12</pre><p> </p><p><strong>提示：</strong></p><ul>	<li><code>m == grid.length</code></li>	<li><code>n == grid[i].length</code></li>	<li><code>1 <= m, n <= 200</code></li>	<li><code>0 <= grid[i][j] <= 100</code></li></ul>

## template

```python
class Solution(object):
	def minPathSum(self, grid):
		"""
		:type grid: List[List[int]]
		:rtype: int
		"""
		height = len(grid)
		if height == 0:
			return 0
		width = len(grid[0])
		pathmap = []
		for i in range(height):
			pathmap.append([100000000000] * width)
		pathmap[0][0] = grid[0][0]
		for i in range(height):
			for j in range(width):
				compare = [pathmap[i][j]]
				if i - 1 >= 0:
					compare.append(pathmap[i - 1][j] + grid[i][j])
				if j - 1 >= 0:
					compare.append(pathmap[i][j - 1] + grid[i][j])
				pathmap[i][j] = min(compare)
		return pathmap[-1][-1]
# %%
s = Solution()
print(s.minPathSum(grid = [[1,3,1],[1,5,1],[4,2,1]]))
```

## 答案

```python

```

## 选项

### A

```python

```

### B

```python

```

### C

```python

```