Skip to content

Commit ec2350c

Browse files
author
Eric
committed
94차 1번 문제풀이
1 parent bcbcb2c commit ec2350c

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

live9/test94/문제1/황장현.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)