Python Recursive


  • 0
    G
    # Definition for a binary tree node.
    # class TreeNode(object):
    #     def __init__(self, x):
    #         self.val = x
    #         self.left = None
    #         self.right = None
    
    class Solution(object):
        def convertBST(self, root):
            """
            :type root: TreeNode
            :rtype: TreeNode
            """
            self.change(root,0)
            return root
            
        
        def change(self,root,add):
            
            if not root:
                return add
            right = self.change(root.right,add)
            root.val += right
            left  = self.change(root.left,root.val)
            return left

Log in to reply
 

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