We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent e191d33 commit f2908c7Copy full SHA for f2908c7
1 file changed
live8/test87/문제3/황장현.js
@@ -0,0 +1,31 @@
1
+function solution(dirs) {
2
+ let x = 0;
3
+ let y = 0;
4
+
5
+ const visited = new Set();
6
+ const directions = {
7
+ U: [0, 1],
8
+ D: [0, -1],
9
+ L: [-1, 0],
10
+ R: [1, 0],
11
+ };
12
13
+ for (let dir of dirs) {
14
+ const [dx, dy] = directions[dir];
15
+ let nx = x + dx;
16
+ let ny = y + dy;
17
18
+ if (nx < -5 || nx > 5 || ny < -5 || ny > 5) continue;
19
20
+ const path = `[${x},${y}]->[${nx},${ny}]`;
21
22
+ visited.add(path);
23
24
+ x = nx;
25
+ y = ny;
26
+ }
27
28
+ return visited.size;
29
+}
30
31
+console.log(solution('ULURRDLLU'));
0 commit comments