[프로그래머스] 단어 변환 파이썬 (BFS/DFS)
고급 from collections import deque as queue transistable = lambda a,b: sum((1 if x!=y else 0) for x,y in zip(a,b)) == 1 def solution(begin,target,words): q, d = queue(), dict() q.append((begin, 0)) d[begin] = set(filter(lambda x:transistable(x,begin), words)) for w in words: d[w] = set(filter(lambda x:transistable(x,w), words)) while q: cur, level = q.popleft() if level > len(words): return 0 for ..
2021. 3. 17.