Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python invert binary tree

from collections import deque
def levelOrderTraversal(root):
    q = deque()
    q.append(root)
    while q:
        curr = q.popleft()
        print(curr.data, end=' ')
        if curr.left:
            q.append(curr.left)
        if curr.right:
            q.append(curr.right)
Comment

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
Comment

PREVIOUS NEXT
Code Example
Python :: how to check if character in string python 
Python :: uninstall a python package from virtualenv 
Python :: multiple figures matplotlib 
Python :: type checking python 
Python :: piecewise linear regression python 
Python :: invert list python 
Python :: python requests post form data 
Python :: how to remove element from nested list in python 
Python :: python enumerate unique values 
Python :: bmi calculator in python 
Python :: tensorflow inst for python 3.6 
Python :: numpy concatenation 
Python :: python list last element 
Python :: all python functions 
Python :: python modules 
Python :: check all true python 
Python :: .lift tkinter 
Python :: insert data in sqlite database in python 
Python :: read api from django 
Python :: odoo sorted 
Python :: turtle graphics documentation|pensize 
Python :: sort python 
Python :: palindrome checker python 
Python :: Login script using Python and SQLite 
Python :: python convert b string to dict 
Python :: ajouter element liste python 
Python :: yml anaconda 
Python :: decimal to binary python 
Python :: binary to decimal in python without inbuilt function 
Python :: python unittest coverage main function 
ADD CONTENT
Topic
Content
Source link
Name
3+1 =