python - greater tree


  • 0
    S
    # 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 inorder(self, root, run_sum):
            if not root:
                return run_sum
            
            root.val += self.inorder(root.right, run_sum)
            return self.inorder(root.left, root.val)
            
        def convertBST(self, root):
            """
            :type root: TreeNode
            :rtype: TreeNode
            """
            self.inorder(root, 0)
            return root
    

Log in to reply
 

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