문자열 압축 - pyhton(programmers)

참치돌고래·2021년 8월 30일
0

알고리즘

목록 보기
14/36
post-custom-banner

https://programmers.co.kr/learn/courses/30/lessons/60057


from collections import deque
from difflib import SequenceMatcher

def solution(begin, target, words):
    
    answer = 0
    queue= deque()
    n = len(words)
    nn=len(words[0])
    if target not in words:
        return answer
    else:
        queue.append([begin,0])
        #print(begin)
        while queue:
            temp,answer = queue.popleft()
            answer +=1
            if temp == target:
                return answer-1
            for i in range(n):
                ratio=SequenceMatcher(None, temp, words[i]).ratio()
                if ratio == (nn-1)/nn:
                    queue.append([words[i],answer])
                    print(words[i])
                    print(answer)
        return answer-1            
                    
    
    return answer


profile
안녕하세요
post-custom-banner

0개의 댓글