Update 面试总结.md
This commit is contained in:
parent
25d27ddaca
commit
99591d3adb
@ -470,15 +470,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. 二叉树的下一个结点
|
||||
|
Loading…
x
Reference in New Issue
Block a user