Python Inorder DFS


  • 0
    class Solution(object):
        def convertBST(self, root):
            """
            :type root: TreeNode
            :rtype: TreeNode
            """
            self.prev = 0
            def inorderDFS(node):
                if node:
                    inorderDFS(node.right)
                    node.val += self.prev
                    self.prev = node.val
                    inorderDFS(node.left)
            inorderDFS(root)
            return root
    

Log in to reply
 

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