We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent bcbcb2c commit ec2350cCopy full SHA for ec2350c
1 file changed
live9/test94/문제1/황장현.js
@@ -0,0 +1,32 @@
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'));
32
+// console.log(solution('LULLLLLLU'));
0 commit comments