Merge branch 'haiker2011-patch-ownInterview' of https://github.com/haiker2011/Interview-Notebook into haiker2011-patch-ownInterview

This commit is contained in:
haiker2011 2018-09-27 20:33:52 +08:00
commit 1b72a42820

View File

@ -475,15 +475,15 @@ private TreeNode reConstructBinaryTree(int[] pre, int preL, int preR, int inL) {
```python
# 返回构造的TreeNode根节点
def reConstructBinaryTree(self, pre, tin):
# write code here
if not pre or not tin:
return None
root = TreeNode(pre.pop(0))
index = tin.index(root.val)
root.left = self.reConstructBinaryTree(pre, tin[:index])
root.right = self.reConstructBinaryTree(pre, tin[index + 1:])
return root
def reConstructBinaryTree(self, pre, tin):
# write code here
if not pre or not tin:
return None
root = TreeNode(pre.pop(0))
index = tin.index(root.val)
root.left = self.reConstructBinaryTree(pre, tin[:index])
root.right = self.reConstructBinaryTree(pre, tin[index + 1:])
return root
```
# 8. 二叉树的下一个结点