You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
DFS로 조금 지저분하게 풀었는데 BFS가 더 깔끔할거 같긴 하다.
DFS는 오른쪽 노드로 간 경로와 왼쪽 노드로 간 경로를 비교한 다음 오른쪽에서 본 것처럼 덮어 씌우는 방식으로 구현하였다. (문제 설명 그대로 오른쪽에서 보는 방식이다. 이런 문제 풀때 그닥 좋지는 않지만 직관적인 방법)
BFS는 레벨별로 큐에 집어넣은 다음 큐의 가장 오른쪽 노드만 뽑는 방식이다. 이게 코드도 더 깔끔함.
This discussion was converted from issue #80 on September 15, 2026 11:06.
Heading
Bold
Italic
Quote
Code
Link
Numbered list
Unordered list
Task list
Attach files
Mention
Reference
Menu
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Problem link
https://leetcode.com/problems/binary-tree-right-side-view/
Problem Summary
이진 트리가 주어질 때 오른쪽에서 볼 때 보이는 노드들을 출력하는 문제.
Solution
DFS로 조금 지저분하게 풀었는데 BFS가 더 깔끔할거 같긴 하다.
DFS는 오른쪽 노드로 간 경로와 왼쪽 노드로 간 경로를 비교한 다음 오른쪽에서 본 것처럼 덮어 씌우는 방식으로 구현하였다. (문제 설명 그대로 오른쪽에서 보는 방식이다. 이런 문제 풀때 그닥 좋지는 않지만 직관적인 방법)
BFS는 레벨별로 큐에 집어넣은 다음 큐의 가장 오른쪽 노드만 뽑는 방식이다. 이게 코드도 더 깔끔함.
다른 사용자 풀이 보니 postorder로도 풀었는데 이것도 깔끔하다.
Source Code
DFS
BFS
All reactions