Skip to content

vishnuvardhanreddy31/GFG_POTD_SOLUTIONS

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 

Repository files navigation

Level order traversal

18-03-2024

Python Solution

from collections import deque

class Solution:
    #Function to return the level order traversal of a tree.
    def levelOrder(self,root):
        # Code here
        if root is None:
            return []

        q=deque()
        out=[]
        q.append(root)
        while q:
            front = q.popleft()
            out.append(front.data)

            if front.left:
                q.append(front.left)
            if front.right:
                q.append(front.right)

        return out

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages