Skip to content

Commit ebe366e

Browse files
committed
102차 3번 문제풀이
1 parent acf9668 commit ebe366e

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
function solution(x, y, n) {
2+
const visited = new Set([x]);
3+
const queue = [[x, 0]];
4+
let queueIndex = 0;
5+
6+
while (queueIndex < queue.length) {
7+
const [current, count] = queue[queueIndex++];
8+
if (current === y) return count;
9+
10+
const calculate = [current + n, current * 2, current * 3];
11+
12+
for (const cal of calculate) {
13+
if (cal <= y && !visited.has(cal)) {
14+
visited.add(cal);
15+
queue.push([cal, count + 1]);
16+
}
17+
}
18+
}
19+
20+
return -1;
21+
}
22+
23+
console.log(solution(10, 40, 30));

0 commit comments

Comments
 (0)