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 }