I am trying to solve this problem in leetcode using Go. The following code is not working. Please help me understand what I am missing.
https://leetcode.com/problems/increasing-order-search-tree/
func increasingBST(root *TreeNode) *TreeNode {
var newRoot = TreeNode{Val:0}
var currentNode = TreeNode{Val:0}
recur(root, ¤tNode, &newRoot)
return &newRoot
}
func recur(root *TreeNode, currentNode *TreeNode, newRoot *TreeNode) {
if root == nil {
return
}
recur(root.Left, currentNode, newRoot)
if newRoot.Val == 0 {
currentNode = root
newRoot = currentNode
root.Left = nil
} else {
root.Left = nil
currentNode.Right = root
currentNode = currentNode.Right
}
recur(root.Right, currentNode, newRoot)
}
Comments
Post a Comment