일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | |
7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 |
Tags
- 괜찮음
- 프로젝트
- 운동
- Daily Challenge
- 10분
- Writing
- 뭐든
- 읽기
- 리얼 클래스
- 사이드
- realclass
- 30분
- FIT XR
- 스탭퍼
- 화상영어
- Problem Solving
- 만화도
- 파비최
- 잡생각
- 미드시청
- 영어원서읽기
- 개발자
- 영어공부
- 매일
- 쓰릴오브파이트
- 3줄정리
- English
- 링피트
- leetcode
- 월간
Archives
- Today
- Total
파비의 매일매일 공부기록
Today's Challenge 본문
https://leetcode.com/problems/binary-tree-right-side-view/
Binary Tree Right Side View - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
트리 문제는 일단 나오면 살짝 긴장...
오늘도 결국 솔루션을 보긴 했으나, 생각보다 간단한 구조로 풀릴 수 있다는걸 알게됨.
(변형된 전위 순회를 하면 된다는 거 까지는 대충 눈치 챘는데 ㅠㅠ)
class Solution:
def rightSideView(self, root: Optional[TreeNode]) -> List[int]:
def solve(r, l):
if r:
if len(res) == l:
res.append(r.val)
solve(r.right, l+1)
solve(r.left, l+1)
return
res = []
solve(root, 0)
return res
반응형
'Problem Solving > LeetCode' 카테고리의 다른 글
Today's Challenge (0) | 2022.07.13 |
---|---|
Today's Challenge (0) | 2022.07.12 |
Today's Challenge (0) | 2022.07.10 |
Today's Challenge (0) | 2022.07.09 |
Today's Challenge (0) | 2022.07.08 |
Comments