We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 30e1752 commit b991a08Copy full SHA for b991a08
C++/alphabet-board-path.cpp
@@ -0,0 +1,20 @@
1
+// Time: O(n)
2
+// Space: O(1)
3
+
4
+class Solution {
5
+public:
6
+ string alphabetBoardPath(string target) {
7
+ string result;
8
+ int x = 0, y = 0;
9
+ for (const auto& c : target) {
10
+ int x1 = (c - 'a') % 5, y1 = (c - 'a') / 5;
11
+ result += string(max(y - y1, 0), 'U');
12
+ result += string(max(x - x1, 0), 'L');
13
+ result += string(max(x1 - x, 0), 'R');
14
+ result += string(max(y1 - y, 0), 'D');
15
+ result += "!";
16
+ x = x1, y = y1;
17
+ }
18
+ return result;
19
20
+};
0 commit comments