Skip to content

Commit 217b9aa

Browse files
authored
Merge pull request #603 from eric-hjh/main
[황장현] 87차 라이브 코테 제출
2 parents ce52550 + f2908c7 commit 217b9aa

2 files changed

Lines changed: 51 additions & 0 deletions

File tree

live8/test87/문제1/황장현.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
function solution(numbers) {
2+
const result = new Array(numbers.length).fill(-1);
3+
const stack = [];
4+
5+
for (let i = numbers.length - 1; i >= 0; i--) {
6+
while (stack.length > 0 && stack[stack.length - 1] <= numbers[i]) {
7+
stack.pop();
8+
}
9+
10+
if (stack.length > 0) {
11+
result[i] = stack[stack.length - 1];
12+
}
13+
14+
stack.push(numbers[i]);
15+
}
16+
17+
return result;
18+
}
19+
20+
console.log(solution([9, 1, 5, 3, 6, 2]));

live8/test87/문제3/황장현.js

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

Comments
 (0)