modified inorder traversal

  • 1
    # 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
            def _sum(root,xsum):
                if root:
                    rt = _sum(root.right,xsum)
                    root.val = root.val + rt
                    lt = _sum(root.left, root.val)
                    return lt
                return xsum
            return root

  • 0

    Great solution!!!
    Can you add some explanation??

Log in to reply

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