题解 | #二叉搜索树与双向链表#

二叉搜索树与双向链表

https://www.nowcoder.com/practice/947f6eb80d944a84850b0538bf0ec3a5

/* function TreeNode(x) {
    this.val = x;
    this.left = null;
    this.right = null;
} */
function Convert(pRootOfTree)
{
    // write code here
    if (pRootOfTree === null) return null
    const array = []
    inOrder(pRootOfTree, array)
    for (let i = 0; i < array.length - 1; i++) {
        array[i].right = array[i + 1]
        array[i + 1].left = array[i]
    }
    return array[0]
}

function inOrder(root, array) {
    if (root === null) return
    inOrder(root.left, array)
    array.push(root)
    inOrder(root.right, array)
}

module.exports = {
    Convert : Convert
};

全部评论

相关推荐

12-19 20:28
已编辑
门头沟学院 Java
美团履约 全栈工程师 (n+1)*15.5 其他
点赞 评论 收藏
分享
dachang盒子:26届秋招必须有实习经历,建议找个实习过度下,同时项目重复率也比较高没有什么难点亮点,我这里有大厂真实的项目可以提供给你学习也可以给你包装大厂实习来提高你的竞争力,感兴趣的话可以私信我或者点我主页简介
你已经投递多少份简历了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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