상위 150개 인터뷰중간

이진 트리 오른쪽 보기

'Binary Tree Right Side View' 문제에 대한 자세한 가이드 및 Python 구현입니다.

문제 설명

중간

이진 트리의 루트가 주어지면 자신이 루트의 오른쪽에 서 있다고 상상하고 위에서 아래로 정렬된 노드 값을 반환합니다.

트리는 레벨 순서 목록으로 표시됩니다. rightSideView(root: list) -> list 함수를 구현하세요.

제약
  • The number of nodes in the tree is in the range [0, 100]
  • -100 <= Node.val <= 100

Example 1
Input
[1,2,3,None,5,None,4]
Output
[1,3,4]
Explanation

From the right side: at level 0 you see 1, at level 1 you see 3, at level 2 you see 4.

Example 2
Input
[1,None,3]
Output
[1,3]
Explanation

From the right side: at level 0 you see 1, at level 1 you see 3.

Example 3
Input
[]
Output
[]
Explanation

Empty tree, nothing to see.

Need a Hint?
세트나 힙과 같은 트리 관련 데이터 구조를 사용해 보세요.
Edge Cases to Watch
  • 빈 입력 구조
  • 단일 요소 입력
  • 큰 수치 범위

해결할 준비가 되셨나요?

Open the problem in PyRun's browser-based Python editor. Your code runs fully offline — no server required.

편집기에서 열기
Found this breakdown helpful?

PyRun is built and maintained by an independent solo developer. If this helped your interview prep, consider buying a coffee!

Buy me a coffee

권장 Python 리소스

관련 대화형 튜토리얼, 치트 시트, 코드 비교를 통해 지식을 확장하세요.