Skip to content

Latest commit

 

History

History
99 lines (42 loc) · 2.08 KB

File metadata and controls

99 lines (42 loc) · 2.08 KB

中文文档

Description

On an alphabet board, we start at position (0, 0), corresponding to character board[0][0].

Here, board = ["abcde", "fghij", "klmno", "pqrst", "uvwxy", "z"], as shown in the diagram below.

We may make the following moves:

    <li><code>&#39;U&#39;</code> moves our position up one row, if the position exists on the board;</li>
    
    <li><code>&#39;D&#39;</code> moves our position down one row, if the position exists on the board;</li>
    
    <li><code>&#39;L&#39;</code> moves our position left one column, if the position exists on the board;</li>
    
    <li><code>&#39;R&#39;</code> moves our position right one column, if the position exists on the board;</li>
    
    <li><code>&#39;!&#39;</code>&nbsp;adds the character <code>board[r][c]</code> at our current position <code>(r, c)</code>&nbsp;to the&nbsp;answer.</li>
    

(Here, the only positions that exist on the board are positions with letters on them.)

Return a sequence of moves that makes our answer equal to target in the minimum number of moves.  You may return any path that does so.

 

Example 1:

Input: target = "leet"

Output: "DDR!UURRR!!DDD!"

Example 2:

Input: target = "code"

Output: "RR!DDRR!UUL!R!"

 

Constraints:

    <li><code>1 &lt;= target.length &lt;= 100</code></li>
    
    <li><code>target</code> consists only of English lowercase letters.</li>
    

Solutions

Python3

Java

...