题解 | #二叉搜索树与双向链表#
二叉搜索树与双向链表
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
}

