Merged
Conversation
sik9252
approved these changes
Mar 18, 2026
Collaborator
There was a problem hiding this comment.
DFS 재귀로 최대 깊이를 구하는 정석 풀이로 깔끔하게 잘 작성하신 것 같습니다. null 처리와 Math.max(left, right) + 1 흐름도 명확해서 읽기 좋았어요.
Collaborator
There was a problem hiding this comment.
오 이렇게 Map으로 인덱스와 노드를 저장해서 middle을 찾는 방식으로도 구현할 수 있군요 알아갑니다!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
이렇게 풀었어요
1. Middle of the Linked List
1) 복잡도 계산
2) 접근 아이디어
3) 회고
처음에는 index를 직접 세고 Map에 노드를 저장해서 가운데 노드를 찾는 방식으로 풀었다. 구현 자체는 직관적이었는데, 문제를 풀고 나니 굳이 노드를 전부 저장하지 않아도 된다는 점이 아쉽게 느껴졌다. 토끼와 거북이 패턴을 알고는 있었지만, 막상 연결 리스트 문제에 바로 적용하려고 하니 아직은 시간이 더 필요한 것 같다.
다른 사람 풀이:
다른 사람 풀이 핵심: 풀이 흐름을 단계별로 분리해 조건 확인과 상태 갱신을 명확히 나눈 점이 핵심이었다.
내 생각: slow, fast 포인터만으로 가운데를 찾는 방식이 훨씬 간결했다. 다음에는 연결 리스트가 나오면 Map으로 저장하기 전에 토끼와 거북이 패턴을 먼저 떠올려보려고 한다.
2. Maximum Depth of Binary Tree
1) 복잡도 계산
2) 접근 아이디어
3) 회고
DFS 문제가 리트코드처럼 자료 구조가 달라지면 적응하는 게 아직 어렵다. 그래도
depth(node) = max(depth(left), depth(right)) + 1공식을 기준으로 보니까 조금씩 정리가 됐다. 핵심은 depth가 아래로 전달되는 값이 아니라, 리프에서부터 계산돼서 위로 올라오는 값이라는 점이었다.다른 사람 풀이:
다른 사람 풀이 핵심: 탐색 순서를 명확히 제어하면서 방문 조건을 먼저 처리해 예외 케이스를 안정적으로 막은 점이 핵심이었다.
내 생각: depth를 반환값으로 처리하는 방식이 더 익숙했는데, 깊이를 인자로 내려보내며 최대값을 갱신하는 풀이도 가능하다는 점이 흥미로웠다. 같은 DFS라도 상태를 어디에 둘지에 따라 풀이 모양이 꽤 달라진다는 걸 느꼈다.