Merge pull request #121 from faiz-lab/master

添加0106.从中序与后序遍历序列构造二叉树 JavaScript版代码
This commit is contained in:
Carl Sun
2021-05-14 15:34:09 +08:00
committed by GitHub

View File

@ -623,7 +623,21 @@ Python
Go
JavaScript
```javascript
var buildTree = function(inorder, postorder) {
if (!postorder.length) return null
let root = new TreeNode(postorder[postorder.length - 1])
let index = inorder.findIndex(number => number === root.val)
root.left = buildTree(inorder.slice(0, index), postorder.slice(0, index))
root.right = buildTree(inorder.slice(index + 1, inorder.length), postorder.slice(index, postorder.length - 1))
return root
};
```
-----------------------
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)