diff options
author | Jack Sangdahl <[email protected]> | 2025-06-27 12:23:02 -0600 |
---|---|---|
committer | Jack Sangdahl <[email protected]> | 2025-06-27 12:23:02 -0600 |
commit | a96b65cbfad7f62f3db6b2eab105e4e25c0414c5 (patch) | |
tree | e2a2b3f49f9fb741be81415266ac93e74cff42ec /other/alphabet_board_path.cpp | |
parent | 694ad5ed71edcb1deccab54b72d706b779918276 (diff) | |
download | leetcode-a96b65cbfad7f62f3db6b2eab105e4e25c0414c5.tar.gz leetcode-a96b65cbfad7f62f3db6b2eab105e4e25c0414c5.zip |
chore: remove old cpp and rust solutions
Diffstat (limited to 'other/alphabet_board_path.cpp')
-rw-r--r-- | other/alphabet_board_path.cpp | 44 |
1 files changed, 0 insertions, 44 deletions
diff --git a/other/alphabet_board_path.cpp b/other/alphabet_board_path.cpp deleted file mode 100644 index 874e201..0000000 --- a/other/alphabet_board_path.cpp +++ /dev/null @@ -1,44 +0,0 @@ -// 1138. Alphabet Board Path -#include "leetcode.h" - -/* - * on an alphabet board, we start position [0,0], corresponding to character - * 'board[0][0]'. here, 'board = ["abcde", "fghij", "klmno", "pqrst", "uvwxy", - * "z"]' as show in the diagram (see page). return a sequence of moves that - * makes our answer equal to 'target' in the minimum numbe of moves. (in any - * order/path) - */ - -class Solution { -public: - string alphabetBoardPath(string target) { - unordered_map<char, pair<int, int>> mp; - for (int i = 0; i < 26; ++i) - mp[i + 'a'] = {i / 5, i % 5}; - target = 'a' + target; - string path; - int dx = 0, dy = 0; - for (int i = 1; i < target.size(); ++i) { - auto curr = mp[target[i]]; - auto prev = mp[target[i - 1]]; - dx = curr.first - prev.first; - dy = curr.second - prev.second; - if (dy < 0) - path += string(-dy, 'L'); - if (dx < 0) - path += string(-dx, 'U'); - if (dy > 0) - path += string(dy, 'R'); - if (dx > 0) - path += string(dx, 'D'); - path += '!'; - } - return path; - } -}; - -int main() { - Solution boj; - cout << boj.alphabetBoardPath("leet") << endl; // expect: DDR!UURRR!!DDD! - cout << boj.alphabetBoardPath("code") << endl; // expect: RR!DDRR!UUL!R! -} |