🔑 오늘의 학습 키워드 bfs
🔗 문제링크 https://school.programmers.co.kr/learn/courses/30/lessons/43163
def solution(begin, target, words):
# 못찾는 경우
if target not in set(words):
return 0
answer = 0
stack = [(begin,0)]
visited = set()
visited.add(begin)
while stack:
start,cnt = stack.pop()
for word in words:
if word not in visited:
wrong_cnt = 0
is_diff_one = True
for i,j in zip(start, word):
if i != j:
wrong_cnt += 1
if wrong_cnt > 1:
is_diff_one = False
break
if is_diff_one:
if word == target:
return cnt + 1
stack.append((word,cnt + 1))
visited.add(word)
#99클럽 #코딩테스트준비 #개발자취업 #항해99 #TIL
'Coding test' 카테고리의 다른 글
99클럽 코테 스터디 35일차 TIL, 프로그래머스 / 퍼즐 조각 채우기 (0) | 2024.08.25 |
---|---|
99클럽 코테 스터디 34일차 TIL, 프로그래머스 / 여행경로 (0) | 2024.08.24 |
99클럽 코테 스터디 32일차 TIL, 프로그래머스 / 아이템 줍기 (0) | 2024.08.22 |
99클럽 코테 스터디 31일차 TIL, 프로그래머스 / 네트워크 (0) | 2024.08.21 |
99클럽 코테 스터디 30일차 TIL, leetcode / Minimum Operations to Make a Subsequence (0) | 2024.08.20 |