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
|
```python
|
||||||
# 返回构造的TreeNode根节点
|
# 返回构造的TreeNode根节点
|
||||||
def reConstructBinaryTree(self, pre, tin):
|
def reConstructBinaryTree(self, pre, tin):
|
||||||
# write code here
|
# write code here
|
||||||
if not pre or not tin:
|
if not pre or not tin:
|
||||||
return None
|
return None
|
||||||
root = TreeNode(pre.pop(0))
|
root = TreeNode(pre.pop(0))
|
||||||
index = tin.index(root.val)
|
index = tin.index(root.val)
|
||||||
root.left = self.reConstructBinaryTree(pre, tin[:index])
|
root.left = self.reConstructBinaryTree(pre, tin[:index])
|
||||||
root.right = self.reConstructBinaryTree(pre, tin[index + 1:])
|
root.right = self.reConstructBinaryTree(pre, tin[index + 1:])
|
||||||
return root
|
return root
|
||||||
```
|
```
|
||||||
|
|
||||||
# 8. 二叉树的下一个结点
|
# 8. 二叉树的下一个结点
|
||||||
|
Loading…
x
Reference in New Issue
Block a user