{
  "type": "code_options",
  "author": "https://github.com/qiyuangong/leetcode",
  "source": "solution.md",
  "exercise_id": "62b3b65b60fc494283c75e4fdecd2221",
  "keywords": "数组,动态规划,矩阵",
  "title": "最小路径和",
  "desc": [
    {
      "content": "\n<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://cdn.jsdelivr.net/gh/doocs/leetcode@main/solution/0000-0099/0064.Minimum%20Path%20Sum/images/minpath.jpg\" 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>\t<li><code>m == grid.length</code></li>\t<li><code>n == grid[i].length</code></li>\t<li><code>1 <= m, n <= 200</code></li>\t<li><code>0 <= grid[i][j] <= 100</code></li></ul>",
      "language": "markdown"
    }
  ],
  "answer": [
    {
      "content": "",
      "language": "python"
    }
  ],
  "prepared": [
    [
      {
        "content": "",
        "language": "python"
      }
    ],
    [
      {
        "content": "",
        "language": "python"
      }
    ],
    [
      {
        "content": "",
        "language": "python"
      }
    ]
  ],
  "template": {
    "content": "class Solution(object):\n\tdef minPathSum(self, grid):\n\t\t\"\"\"\n\t\t:type grid: List[List[int]]\n\t\t:rtype: int\n\t\t\"\"\"\n\t\theight = len(grid)\n\t\tif height == 0:\n\t\t\treturn 0\n\t\twidth = len(grid[0])\n\t\tpathmap = []\n\t\tfor i in range(height):\n\t\t\tpathmap.append([100000000000] * width)\n\t\tpathmap[0][0] = grid[0][0]\n\t\tfor i in range(height):\n\t\t\tfor j in range(width):\n\t\t\t\tcompare = [pathmap[i][j]]\n\t\t\t\tif i - 1 >= 0:\n\t\t\t\t\tcompare.append(pathmap[i - 1][j] + grid[i][j])\n\t\t\t\tif j - 1 >= 0:\n\t\t\t\t\tcompare.append(pathmap[i][j - 1] + grid[i][j])\n\t\t\t\tpathmap[i][j] = min(compare)\n\t\treturn pathmap[-1][-1]\n# %%\ns = Solution()\nprint(s.minPathSum(grid = [[1,3,1],[1,5,1],[4,2,1]]))",
    "language": "python"
  },
  "node_id": "dailycode-6afc8fbcc3f245aeb6bfea64f87d53ee",
  "license": "csdn.net",
  "created_at": 1637894159,
  "topic_link": "https://bbs.csdn.net/topics/600470227"
}