java容易理解

二叉搜索树与双向链表

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

public class Solution {
    public TreeNode Convert(TreeNode root) {
        if(root == null){
            return null;
        }
        TreeNode newHead = root;
        TreeNode pre;
        if(root.left != null){ //排序左边
             newHead = Convert(root.left);
             pre = newHead;
            while(pre.right != null){
                pre = pre.right;
            }
            pre.right = root;
            root.left = pre;
        }
        if(root.right != null){//排序右边
            pre = Convert(root.right);
            pre.left = root;
            root.right = pre;
        }
        return newHead;
    }
}
全部评论

相关推荐

2025-12-15 14:25
云南大学 Java
lei22:入职可能会看学信网,最好别伪装,这个简历找实习肯定是够的,肯定会有收 28 届实习生的公司的,多投就行
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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