1138. Alphabet Board Path Medium
1/**
2 * [1138] Alphabet Board Path
3 *
4 * On an alphabet board, we start at position (0, 0), corresponding to character board[0][0].
5 *
6 * Here, board = ["abcde", "fghij", "klmno", "pqrst", "uvwxy", "z"], as shown in the diagram below.
7 *
8 * <img alt="" src="https://assets.leetcode.com/uploads/2019/07/28/azboard.png" style="width: 250px; height: 317px;" />
9 *
10 * We may make the following moves:
11 *
12 *
13 * 'U' moves our position up one row, if the position exists on the board;
14 * 'D' moves our position down one row, if the position exists on the board;
15 * 'L' moves our position left one column, if the position exists on the board;
16 * 'R' moves our position right one column, if the position exists on the board;
17 * '!' adds the character board[r][c] at our current position (r, c) to the answer.
18 *
19 *
20 * (Here, the only positions that exist on the board are positions with letters on them.)
21 *
22 * 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.
23 *
24 *
25 * Example 1:
26 * Input: target = "leet"
27 * Output: "DDR!UURRR!!DDD!"
28 * Example 2:
29 * Input: target = "code"
30 * Output: "RR!DDRR!UUL!R!"
31 *
32 *
33 * Constraints:
34 *
35 *
36 * 1 <= target.length <= 100
37 * target consists only of English lowercase letters.
38 *
39 */
40pub struct Solution {}
41
42// problem: https://leetcode.com/problems/alphabet-board-path/
43// discuss: https://leetcode.com/problems/alphabet-board-path/discuss/?currentPage=1&orderBy=most_votes&query=
44
45// submission codes start here
46
47impl Solution {
48 pub fn alphabet_board_path(target: String) -> String {
49 String::new()
50 }
51}
52
53// submission codes end
54
55#[cfg(test)]
56mod tests {
57 use super::*;
58
59 #[test]
60 fn test_1138() {
61 }
62}
63
Back
© 2025 bowen.ge All Rights Reserved.