Skip to content

Commit

Permalink
rename
Browse files Browse the repository at this point in the history
  • Loading branch information
rinwf committed Mar 15, 2019
1 parent 932c5d4 commit 67f35a6
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions 106. Construct Binary Tree from Inorder and Postorder Traversal.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None

class Solution:
def buildTree(self, inorder, postorder):
"""
:type inorder: List[int]
:type postorder: List[int]
:rtype: TreeNode
"""
if not postorder:
return None
i = inorder.index(postorder[-1])
root=postorder[-1]
root.left=self.buildTree(inorder[:i], postorder[:i])
root.right=self.buildTree(inorder[i+1:],postorder[i:-1])
return root

0 comments on commit 67f35a6

Please sign in to comment.