Skip to content

Commit f714991

Browse files
committed
104차 3번 문제풀이
1 parent 0e69dcc commit f714991

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
function solution(begin, target, words) {
2+
let visit = [];
3+
let box = [];
4+
box.push([begin, 0]);
5+
6+
while (box.length > 0) {
7+
let now = box.shift();
8+
let txt = now[0];
9+
let cnt = now[1];
10+
11+
if (txt === target) {
12+
return cnt;
13+
}
14+
15+
for (let i = 0; i < words.length; i++) {
16+
let word = words[i];
17+
let diff = 0;
18+
for (let j = 0; j < word.length; j++) {
19+
if (txt[j] !== word[j]) {
20+
diff++;
21+
}
22+
}
23+
24+
if (diff === 1 && !visit.includes(word)) {
25+
visit.push(word);
26+
box.push([word, cnt + 1]);
27+
}
28+
}
29+
}
30+
31+
return 0;
32+
}

0 commit comments

Comments
 (0)