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

二叉搜索树与双向链表

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

二叉树中序遍历

/* function TreeNode(x) {
    this.val = x;
    this.left = null;
    this.right = null;
} */
function Convert(pRootOfTree)
{
    let head = null; //指向链表首节点
    let pre = null; //指向遍历节点的上一节点
    const dfs = (root) => {
        if(!root) return;
        dfs(root.left);
        root.left = pre;
        if(!pre){
             head = root; //root是最小节点
        }else{
            pre.right = root;
        }
        pre = root;
        dfs(root.right);
    }
    dfs(pRootOfTree);
    return head;
}
module.exports = {
    Convert : Convert
};
全部评论

相关推荐

05-20 13:59
门头沟学院 Java
米黑子米黑子:你这个成绩不争取下保研?
点赞 评论 收藏
分享
06-10 21:15
门头沟学院 Java
宁阿:好多这种没🧠的公司,他们估计都不知道毕业的人不能给安排实习岗
实习吐槽大会
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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