본문 바로가기
알고리즘/소스코드

PROGRAMMERS 43163: 단어 변환

by cjw.git 2021. 1. 11.

Link : programmers.co.kr/learn/courses/30/lessons/43163


Python

더보기
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
def check(str1, str2):
    if len(str1) != len(str2):
        return False
 
    counter = 0
    for i in range(len(str1)):
        if str1[i] != str2[i]:
            counter += 1
    return True if counter == 1 else False
 
 
def solution(begin, target, words):
    queue = []
    queue.append((begin, 0))
 
    while len(queue):
        data = queue.pop(0)
        if data[0== target:
            return data[1]
        for idx, val in enumerate(words):
            if check(data[0], val):
                queue.append((val, data[1+ 1))
                words.pop(idx)
    return 0
cs

FeedBack

  1.  

 

 

 

cjw.git@gmail.com

댓글