Simple python


  • 0
    X
    def __init__(self):
        self.sum = 0
        
    def convertBST(self, root):
        if not root:
            return None
        right = self.convertBST(root.right)
        self.sum += root.val
        ret = TreeNode(self.sum)
        left = self.convertBST(root.left)
        ret.left = left
        ret.right = right
        
        return ret

Log in to reply
 

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