Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f729634

Browse filesBrowse files
Create 106.py
1 parent 677959f commit f729634
Copy full SHA for f729634

File tree

1 file changed

+15
-0
lines changed
Filter options

1 file changed

+15
-0
lines changed

‎001-500/106.py

Copy file name to clipboard
+15Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Definition for a binary tree node.
2+
# class TreeNode:
3+
# def __init__(self, val=0, left=None, right=None):
4+
# self.val = val
5+
# self.left = left
6+
# self.right = right
7+
class Solution:
8+
def buildTree(self, inorder: List[int], postorder: List[int]) -> Optional[TreeNode]:
9+
if not inorder:
10+
return None
11+
root = TreeNode(postorder.pop())
12+
mid = inorder.index(root.val)
13+
root.left = self.buildTree(inorder[:mid], postorder[:mid])
14+
root.right = self.buildTree(inorder[mid+1:], postorder[mid:])
15+
return root

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.