Golang reverse inorder


  • 0
    A
    func convertBST(root *TreeNode) *TreeNode {
        node, _ := traverse(root, 0)
        return node
    }
    
    func traverse(root *TreeNode, sum int) (*TreeNode, int){
        if root == nil {
            return nil, sum
        }
        
        _, sum = traverse(root.Right, sum)
        root.Val += sum
        sum = root.Val
        _, sum = traverse(root.Left, sum)
    
        return root, sum
    }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.