Single traversal solution using Inorder nodes Sum,O(N) Complexity


  • 0
    A
    class Solution(object):
        inorder_sum = 0
        def convertBST(self, root):
            if(root != None):
                self.convertBST(root.right)
                root.val += self.inorder_sum
                self.inorder_sum = root.val
                self.convertBST(root.left)
            return root
    

Log in to reply
 

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