[Python] reversed mid-order traversal solution


  • 0
    A
    class Solution(object):
        def __init__(self):
            self.sum = 0  # sum of greater nums
            
        def convertBST(self, root):
            """
            :type root: TreeNode
            :rtype: TreeNode
            """
            self.traversal(root)
            return root
    
        def traversal(self, node):
            if not node:
                return
            self.traversal(node.right)
            val = node.val
            node.val += self.sum
            self.sum += val
            self.traversal(node.left)
    

Log in to reply
 

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