Python recursive solution o(n) time


  • 0
    S
    def convertBST(self, root):
            def bst(root, value = 0):
                if root:
                    value = bst(root.right, value)
                    
                    root.val += value
                    
                    value = bst(root.left, root.val)
                    
                    return value
                return value
            bst(root)
            
            return root
    

Log in to reply
 

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