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 :: display data from database in django 
Python :: dataset for cancer analysis in python 
Python :: matplotlib show plot 
Python :: suppress python 
Python :: matrix inverse python without numpy 
Python :: how call module in the same directory 
Python :: int to ascii python 
Python :: string to array python 
Python :: subtract from dataframe column 
Python :: Play Audio File In Background Python 
Python :: sort dictionary by value and then key python 
Python :: python zip folder 
Python :: python submit work to redis 
Python :: print flush python 
Python :: python run command 
Python :: build a pile of cubes python 
Python :: tokenizer in keras 
Python :: python getters and setters 
Python :: python code with sigma 
Python :: how to execute a python file from another python file 
Python :: how to change frame in tkinter 
Python :: audio streaming python 
Python :: django view - APIView (retrieve, update or delete - GET, PUT, DELETE) 
Python :: get name of month python 
Python :: Simple dictionary in Python 
Python :: python projects with source code 
Python :: pip install covid 
Python :: loop indexing 
Python :: how to add attribute to class python 
Python :: insert data in django models 
ADD CONTENT
Topic
Content
Source link
Name
8+1 =