일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- Problem Solving
- 매일
- 30분
- 개발자
- Daily Challenge
- 스탭퍼
- English
- 운동
- 월간
- realclass
- 파비최
- 10분
- 쓰릴오브파이트
- 링피트
- leetcode
- FIT XR
- 괜찮음
- 리얼 클래스
- 프로젝트
- 화상영어
- 미드시청
- 사이드
- 만화도
- Writing
- 3줄정리
- 읽기
- 영어공부
- 뭐든
- 잡생각
- 영어원서읽기
Archives
- Today
- Total
파비의 매일매일 공부기록
2023.03.16 Today's Challenge 본문
https://leetcode.com/problems/construct-binary-tree-from-inorder-and-postorder-traversal/
Construct Binary Tree from Inorder and Postorder Traversal - LeetCode
Can you solve this real interview question? Construct Binary Tree from Inorder and Postorder Traversal - Given two integer arrays inorder and postorder where inorder is the inorder traversal of a binary tree and postorder is the postorder traversal of the
leetcode.com
트리 순회 문제
class Solution:
def buildTree(self, inorder: List[int], postorder: List[int]) -> Optional[TreeNode]:
if not inorder:
return None
root_val = postorder.pop()
root = TreeNode(root_val)
inorder_index = inorder.index(root_val)
root.right = self.buildTree(inorder[inorder_index + 1:], postorder)
root.left = self.buildTree(inorder[:inorder_index], postorder)
return root
반응형
'Problem Solving > LeetCode' 카테고리의 다른 글
2023.03.18 Today's Challenge (0) | 2023.03.18 |
---|---|
2023.03.17 Today's Challenge (0) | 2023.03.17 |
2023.03.15 Today's Challenge (0) | 2023.03.15 |
2023.03.14 Today's Challenge (0) | 2023.03.14 |
2023.03.13 Today's Challenge (0) | 2023.03.13 |
Comments