일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 31 |
Tags
- Class
- 30. Substring with Concatenation of All Words
- 운영체제
- 시바견
- Python Implementation
- Convert Sorted List to Binary Search Tree
- Substring with Concatenation of All Words
- t1
- Decorator
- 109. Convert Sorted List to Binary Search Tree
- Generator
- 밴픽
- attribute
- iterator
- Protocol
- 315. Count of Smaller Numbers After Self
- shiba
- 프로그래머스
- Python Code
- DWG
- Regular Expression
- 43. Multiply Strings
- kaggle
- 컴퓨터의 구조
- 파이썬
- 715. Range Module
- Python
- data science
- concurrency
- LeetCode
Archives
- Today
- Total
Scribbling
LeetCode: 106. Construct Binary Tree from Inorder and Postorder Traversal 본문
Computer Science/Coding Test
LeetCode: 106. Construct Binary Tree from Inorder and Postorder Traversal
focalpoint 2021. 10. 21. 22:17# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Solution:
def buildTree(self, inorder: List[int], postorder: List[int]) -> Optional[TreeNode]:
return self.builder(inorder, postorder)
def builder(self, inorder, postorder):
if not inorder:
return None
head = TreeNode(val=postorder[-1])
boundary = inorder.index(head.val)
left_inorder = inorder[:boundary]
right_inorder = inorder[boundary+1:]
left_postorder = postorder[:boundary]
right_postorder = postorder[boundary:-1]
head.left = self.builder(left_inorder, left_postorder)
head.right = self.builder(right_inorder, right_postorder)
return head
'Computer Science > Coding Test' 카테고리의 다른 글
프로그래머스: 정수 삼각형 (0) | 2021.10.26 |
---|---|
프로그래머스: N으로 표현 (0) | 2021.10.25 |
프로그래머스: 단속카메라 (0) | 2021.10.21 |
프로그래머스: 섬 연결하기 (0) | 2021.10.21 |
프로그래머스: 구명보트 (0) | 2021.10.21 |