题解 | #重建二叉树#

重建二叉树

http://www.nowcoder.com/practice/8a19cbe657394eeaac2f6ea9b0f6fcf6

function reConstructBinaryTree(pre, vin) {

if(!pre.length || !vin.length) return null;
const root= new TreeNode(pre.shift());
const index=vin.indexOf(root.val);

root.left=reConstructBinaryTree(pre,vin.slice(0,index));

root.right=reConstructBinaryTree(pre,vin.slice(index+1));

return root;

} module.exports = { reConstructBinaryTree : reConstructBinaryTree };

全部评论

相关推荐

Gardenia06...:刚开始学是这样的,可以看看左神和灵神都讲的不错
点赞 评论 收藏
分享
好奇的伊登准备进厂:找了两个多月沟通六千多,不到十个面试至今仍未找到实习,看完你还想坚持下去吗
点赞 评论 收藏
分享
评论
12
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务