Class Solution

java.lang.Object
g1101_1200.s1138_alphabet_board_path.Solution

public class Solution extends Object
1138 - Alphabet Board Path.<p>Medium</p> <p>On an alphabet board, we start at position <code>(0, 0)</code>, corresponding to character <code>board[0][0]</code>.</p> <p>Here, <code>board = [&quot;abcde&quot;, &quot;fghij&quot;, &quot;klmno&quot;, &quot;pqrst&quot;, &quot;uvwxy&quot;, &quot;z&quot;]</code>, as shown in the diagram below.</p> <p><img src="https://assets.leetcode.com/uploads/2019/07/28/azboard.png" alt="" /></p> <p>We may make the following moves:</p> <ul> <li><code>'U'</code> moves our position up one row, if the position exists on the board;</li> <li><code>'D'</code> moves our position down one row, if the position exists on the board;</li> <li><code>'L'</code> moves our position left one column, if the position exists on the board;</li> <li><code>'R'</code> moves our position right one column, if the position exists on the board;</li> <li><code>'!'</code> adds the character <code>board[r][c]</code> at our current position <code>(r, c)</code> to the answer.</li> </ul> <p>(Here, the only positions that exist on the board are positions with letters on them.)</p> <p>Return a sequence of moves that makes our answer equal to <code>target</code> in the minimum number of moves. You may return any path that does so.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> target = &ldquo;leet&rdquo;</p> <p><strong>Output:</strong> &ldquo;DDR!UURRR!!DDD!&rdquo;</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> target = &ldquo;code&rdquo;</p> <p><strong>Output:</strong> &ldquo;RR!DDRR!UUL!R!&rdquo;</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= target.length <= 100</code></li> <li><code>target</code> consists only of English lowercase letters.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details