1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-10-22 05:26:46 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
This commit is contained in:
2022-05-02 23:44:12 +08:00
parent 7ea03594b3
commit 2a71c78585
4790 changed files with 11696 additions and 10944 deletions

View File

@@ -12,7 +12,7 @@
"translatedContent": "<p>给你一个 <code>m x n</code> 的迷宫矩阵 <code>maze</code> <strong>下标从 0 开始</strong>),矩阵中有空格子(用 <code>'.'</code> 表示)和墙(用 <code>'+'</code> 表示)。同时给你迷宫的入口 <code>entrance</code> ,用 <code>entrance = [entrance<sub>row</sub>, entrance<sub>col</sub>]</code> 表示你一开始所在格子的行和列。</p>\n\n<p>每一步操作,你可以往 <strong>上</strong><strong>下</strong><strong>左</strong> 或者 <strong>右</strong> 移动一个格子。你不能进入墙所在的格子,你也不能离开迷宫。你的目标是找到离 <code>entrance</code> <strong>最近</strong> 的出口。<strong>出口</strong> 的含义是 <code>maze</code> <strong>边界</strong> 上的 <strong>空格子</strong>。<code>entrance</code> 格子 <strong>不算</strong> 出口。</p>\n\n<p>请你返回从 <code>entrance</code> 到最近出口的最短路径的 <strong>步数</strong> ,如果不存在这样的路径,请你返回 <code>-1</code> 。</p>\n\n<p> </p>\n\n<p><strong>示例 1</strong></p>\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/06/04/nearest1-grid.jpg\" style=\"width: 333px; height: 253px;\">\n<pre><b>输入:</b>maze = [[\"+\",\"+\",\".\",\"+\"],[\".\",\".\",\".\",\"+\"],[\"+\",\"+\",\"+\",\".\"]], entrance = [1,2]\n<b>输出:</b>1\n<b>解释:</b>总共有 3 个出口,分别位于 (1,0)(0,2) 和 (2,3) 。\n一开始你在入口格子 (1,2) 处。\n- 你可以往左移动 2 步到达 (1,0) 。\n- 你可以往上移动 1 步到达 (0,2) 。\n从入口处没法到达 (2,3) 。\n所以最近的出口是 (0,2) ,距离为 1 步。\n</pre>\n\n<p><strong>示例 2</strong></p>\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/06/04/nearesr2-grid.jpg\" style=\"width: 253px; height: 253px;\">\n<pre><b>输入:</b>maze = [[\"+\",\"+\",\"+\"],[\".\",\".\",\".\"],[\"+\",\"+\",\"+\"]], entrance = [1,0]\n<b>输出:</b>2\n<b>解释:</b>迷宫中只有 1 个出口,在 (1,2) 处。\n(1,0) 不算出口,因为它是入口格子。\n初始时你在入口与格子 (1,0) 处。\n- 你可以往右移动 2 步到达 (1,2) 处。\n所以最近的出口为 (1,2) ,距离为 2 步。\n</pre>\n\n<p><strong>示例 3</strong></p>\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/06/04/nearest3-grid.jpg\" style=\"width: 173px; height: 93px;\">\n<pre><b>输入:</b>maze = [[\".\",\"+\"]], entrance = [0,0]\n<b>输出:</b>-1\n<b>解释:</b>这个迷宫中没有出口。\n</pre>\n\n<p> </p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>maze.length == m</code></li>\n\t<li><code>maze[i].length == n</code></li>\n\t<li><code>1 &lt;= m, n &lt;= 100</code></li>\n\t<li><code>maze[i][j]</code> 要么是 <code>'.'</code> ,要么是 <code>'+'</code> 。</li>\n\t<li><code>entrance.length == 2</code></li>\n\t<li><code>0 &lt;= entrance<sub>row</sub> &lt; m</code></li>\n\t<li><code>0 &lt;= entrance<sub>col</sub> &lt; n</code></li>\n\t<li><code>entrance</code> 一定是空格子。</li>\n</ul>\n",
"isPaidOnly": false,
"difficulty": "Medium",
"likes": 15,
"likes": 17,
"dislikes": 0,
"isLiked": null,
"similarQuestions": "[]",
@@ -149,7 +149,7 @@
"__typename": "CodeSnippetNode"
}
],
"stats": "{\"totalAccepted\": \"5.3K\", \"totalSubmission\": \"14.5K\", \"totalAcceptedRaw\": 5281, \"totalSubmissionRaw\": 14457, \"acRate\": \"36.5%\"}",
"stats": "{\"totalAccepted\": \"5.8K\", \"totalSubmission\": \"15.7K\", \"totalAcceptedRaw\": 5826, \"totalSubmissionRaw\": 15653, \"acRate\": \"37.2%\"}",
"hints": [
"Which type of traversal lets you find the distance from a point?",
"Try using a Breadth First Search."