Skip to content

Commit 0d1632f

Browse files
authored
Merge pull request #606 from sangminlee98/main
[이상민] 87차 라이브 코테 제출
2 parents c6d6c49 + c356f87 commit 0d1632f

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed

live8/test87/문제1/이상민.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
function solution(numbers) {
2+
const answer = Array.from({ length: numbers.length }, () => -1);
3+
const stack = [];
4+
5+
for (let i = 0; i < numbers.length; i++) {
6+
while (stack.length > 0 && numbers[stack.at(-1)] < numbers[i]) {
7+
answer[stack.pop()] = numbers[i];
8+
}
9+
stack.push(i);
10+
}
11+
return answer;
12+
}

live8/test87/문제2/이상민.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
function solution(people, limit) {
2+
let answer = 0;
3+
let left = 0;
4+
let right = people.length - 1;
5+
people.sort((a, b) => a - b);
6+
7+
while (left <= right) {
8+
if (people[left] + people[right] <= limit) {
9+
left++;
10+
right--;
11+
} else {
12+
right--;
13+
}
14+
answer++;
15+
}
16+
return answer;
17+
}

live8/test87/문제3/이상민.js

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

Comments
 (0)