1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-10 18:48:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/字母板上的路径 [alphabet-board-path].html
2022-03-29 12:43:11 +08:00

45 lines
1.6 KiB
HTML
Raw 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>我们从一块字母板上的位置&nbsp;<code>(0, 0)</code>&nbsp;出发,该坐标对应的字符为&nbsp;<code>board[0][0]</code></p>
<p>在本题里,字母板为<code>board = ["abcde", "fghij", "klmno", "pqrst", "uvwxy", "z"]</code>,如下所示。</p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2019/07/28/azboard.png" style="width: 300px;" /></p>
<p>我们可以按下面的指令规则行动:</p>
<ul>
<li>如果方格存在,<code>'U'</code>&nbsp;意味着将我们的位置上移一行;</li>
<li>如果方格存在,<code>'D'</code>&nbsp;意味着将我们的位置下移一行;</li>
<li>如果方格存在,<code>'L'</code>&nbsp;意味着将我们的位置左移一列;</li>
<li>如果方格存在,<code>'R'</code>&nbsp;意味着将我们的位置右移一列;</li>
<li><code>'!'</code>&nbsp;会把在我们当前位置 <code>(r, c)</code> 的字符&nbsp;<code>board[r][c]</code>&nbsp;添加到答案中。</li>
</ul>
<p>(注意,字母板上只存在有字母的位置。)</p>
<p>返回指令序列,用最小的行动次数让答案和目标&nbsp;<code>target</code>&nbsp;相同。你可以返回任何达成目标的路径。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>target = "leet"
<strong>输出:</strong>"DDR!UURRR!!DDD!"
</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>target = "code"
<strong>输出:</strong>"RR!DDRR!UUL!R!"
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= target.length &lt;= 100</code></li>
<li><code>target</code>&nbsp;仅含有小写英文字母。</li>
</ul>