Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

invert binary tree with python

def invertTree(self, root: Optional[TreeNode]) -> Optional[TreeNode]:
    head = root

    def _invert_tree(node):
        if not node:
            return

        node.left, node.right = node.right, node.left
        _invert_tree(node.left)
        _invert_tree(node.right)

    _invert_tree(root)

    return head
Source by eolnuha.com #
 
PREVIOUS NEXT
Tagged: #invert #binary #tree #python
ADD COMMENT
Topic
Name
7+1 =