반응형
https://programmers.co.kr/learn/courses/30/lessons/43163
function solution(begin, target, words) {
var answer = 0;
if(!words.includes(target)) return 0;
let visited = [];
let queue = [];
queue.push([begin, answer])
while(queue.length > 0){
let [word, cnt] = queue.shift();
if(word == target) return cnt;
words.forEach((w)=>{
let diff =0;
if(visited.includes(w)) return;
for(let i=0; i<w.length; i++ ){
if(w[i] !== word[i])
diff++;
}
if(diff === 1){
queue.push([w, cnt+1])
visited.push(word)
}
})
}
return answer;
}
'IT' 카테고리의 다른 글
nginx could not open error log file 13:Permission denied (0) | 2022.04.24 |
---|---|
gradlew 유용한 명령어 (0) | 2022.02.22 |
국내 안드로이드 스마트폰 점유율 (0) | 2022.02.10 |
Reactnative AsyncStorage 데이터 보는법 (0) | 2021.12.03 |
mariadb 암호, 보안 (0) | 2021.10.28 |