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

二叉搜索树与双向链表

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

package main

import . "nc_tools"

func f(root *TreeNode) (head, tail *TreeNode) {
    head, tail = root, root
    if root.Left != nil {
        head, root.Left = f(root.Left)
        root.Left.Right = root
    }
	if root.Right != nil {
        root.Right, tail = f(root.Right)
        root.Right.Left = root
    }
	return
}
func Convert(root *TreeNode) *TreeNode {
    if root == nil {
		return nil
	}
	head, _ := f(root)
	return head
}

全部评论

相关推荐

09-14 20:51
四川大学 Java
慢热的鲸鱼在学习:985加粗就行了,第二个项目来不及准备也没事,省的写了问你你还不会。你只需准备面试八股和项目场景,剩下的交给985。即使面不过也没事,面试经验是最重要的,你现在不缺时间
简历中的项目经历要怎么写
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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