diff --git a/code_study/Baekjoon/ts/1697.ts b/code_study/Baekjoon/ts/1697.ts new file mode 100644 index 0000000..679768f --- /dev/null +++ b/code_study/Baekjoon/ts/1697.ts @@ -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); + } + } +}