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

二叉搜索树与双向链表

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
};
全部评论

相关推荐

2025-12-04 15:23
三峡大学 FPGA工程师
不知道怎么取名字_:玩游戏都写到简历上了啊
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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