We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 4a6161d commit c356f87Copy full SHA for c356f87
1 file changed
live8/test87/문제3/이상민.js
@@ -0,0 +1,31 @@
1
+function validateDir(x, y, dir) {
2
+ switch (dir) {
3
+ case "U":
4
+ return [x, y + 1];
5
+ case "D":
6
+ return [x, y - 1];
7
+ case "R":
8
+ return [x + 1, y];
9
+ case "L":
10
+ return [x - 1, y];
11
+ }
12
+}
13
+
14
+function solution(dirs) {
15
+ const visited = new Set();
16
+ let x = 0;
17
+ let y = 0;
18
19
+ for (dir of dirs) {
20
+ const [nx, ny] = validateDir(x, y, dir);
21
22
+ if (nx >= -5 && nx <= 5 && ny >= -5 && ny <= 5) {
23
+ visited.add(`${x}${y}${nx}${ny}`);
24
+ visited.add(`${nx}${ny}${x}${y}`);
25
+ x = nx;
26
+ y = ny;
27
28
29
30
+ return visited.size / 2;
31
0 commit comments