Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
문제
https://school.programmers.co.kr/learn/courses/30/lessons/154538
풀이 후기
BFS로 풀다가 실패해서 풀이를 찾아봤다.
내가 BFS의 개념 중 잊고 있던 것이 있어 실패했었다 ..
BFS는 최단 거리 찾기 문제에 종종 쓰인다.
한 뎁스씩 가능한 모든 루트를 검사한 뒤 다음 뎁스로 넘어가기 때문에 가장 먼저 발견한 노드가 최단 거리이기 때문이다.
그렇기 때문에 이 문제에서 BFS를 쓸 수 있었던 것인데,
내가 그 사실을 간과한 채 visited를 제대로 활용하지 못했다.
모든 이미 방문한 숫자는 당시의 카운트가 최솟값인 것이며, y 또한 그렇다.