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

二叉搜索树与双向链表

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
}

全部评论

相关推荐

神哥了不得:放平心态,再找找看吧,主要现在计算机也变卷了,然后就比较看学历了,之前高中毕业你技术强,都能找到工作的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务