1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-09-07 08:21:41 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
Files
leetcode-problemset/leetcode-cn/problem (Chinese)/网格传送门旅游 [grid-teleportation-traversal].html
2025-05-25 15:08:47 +08:00

57 lines
2.7 KiB
HTML
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<p>给你一个大小为 <code>m x n</code> 的二维字符网格 <code>matrix</code>,用字符串数组表示,其中 <code>matrix[i][j]</code> 表示第 <code>i</code>&nbsp;行和第 <code>j</code>&nbsp;列处的单元格。每个单元格可以是以下几种字符之一:</p>
<ul>
<li><code>'.'</code> 表示一个空单元格。</li>
<li><code>'#'</code> 表示一个障碍物。</li>
<li>一个大写字母(<code>'A'</code><code>'Z'</code>)表示一个传送门。</li>
</ul>
<p>你从左上角单元格 <code>(0, 0)</code> 出发,目标是到达右下角单元格 <code>(m - 1, n - 1)</code>。你可以从当前位置移动到相邻的单元格(上、下、左、右),移动后的单元格必须在网格边界内且不是障碍物<strong></strong></p>
<p>如果你踏入一个包含传送门字母的单元格,并且你之前没有使用过该传送门字母,你可以立即传送到网格中另一个具有相同字母的单元格。这次传送不计入移动次数,但每个字母对应的传送门在旅程中&nbsp;<strong>最多&nbsp;</strong>只能使用一次。</p>
<p>返回到达右下角单元格所需的&nbsp;<strong>最少&nbsp;</strong>移动次数。如果无法到达目的地,则返回 <code>-1</code></p>
<p>&nbsp;</p>
<p><strong class="example">示例 1</strong></p>
<div class="example-block">
<p><strong>输入:</strong> <span class="example-io">matrix = ["A..",".A.","..."]</span></p>
<p><strong>输出:</strong> 2</p>
<p><strong>解释:</strong></p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2025/03/15/example04140.png" style="width: 151px; height: 151px;" /></p>
<ul>
<li>在第一次移动之前,从 <code>(0, 0)</code> 传送到 <code>(1, 1)</code></li>
<li>第一次移动,从 <code>(1, 1)</code> 移动到 <code>(1, 2)</code></li>
<li>第二次移动,从 <code>(1, 2)</code> 移动到 <code>(2, 2)</code></li>
</ul>
</div>
<p><strong class="example">示例 2</strong></p>
<div class="example-block">
<p><strong>输入:</strong> <span class="example-io">matrix = [".#...",".#.#.",".#.#.","...#."]</span></p>
<p><strong>输出:</strong> <span class="example-io">13</span></p>
<p><strong>解释:</strong></p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2025/03/15/ezgifcom-animated-gif-maker.gif" style="width: 251px; height: 201px;" /></p>
</div>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= m == matrix.length &lt;= 10<sup>3</sup></code></li>
<li><code>1 &lt;= n == matrix[i].length &lt;= 10<sup>3</sup></code></li>
<li><code>matrix[i][j]</code><code>'#'</code><code>'.'</code> 或一个大写英文字母。</li>
<li><code>matrix[0][0]</code> 不是障碍物。</li>
</ul>