20250801 baekjoon
This commit is contained in:
parent
8b2a92e8f3
commit
5dffd3ccab
24
code_study/Baekjoon/ts/1697.ts
Normal file
24
code_study/Baekjoon/ts/1697.ts
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
export {};
|
||||||
|
|
||||||
|
const maxAxis = 100000;
|
||||||
|
const [N, K]: [number, number] = require("fs").readFileSync(0, "utf8").toString().trim().split(' ').map(Number);
|
||||||
|
let queue: number[] = [];
|
||||||
|
let visited: number[] = new Array(maxAxis+1).fill(0);
|
||||||
|
|
||||||
|
queue.push(N);
|
||||||
|
|
||||||
|
while(queue.length){
|
||||||
|
const now = queue.shift();
|
||||||
|
if(now === K){
|
||||||
|
console.log(visited[now]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
const nextAxis: number[] = [now-1, now+1, 2*now];
|
||||||
|
for(let moveAxis of nextAxis){
|
||||||
|
if(0<=moveAxis && moveAxis<=maxAxis && visited[moveAxis]===0){
|
||||||
|
visited[moveAxis] = visited[now] + 1;
|
||||||
|
queue.push(moveAxis);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user