Skip to content

Commit 77a1647

Browse files
author
Parth Shah
authored
#106
1 parent 3c366ec commit 77a1647

File tree

1 file changed

+16
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)