Given the root of a binary tree, return the level order traversal of its nodes' values. (i.e., from left to right, level by level).

&nbsp;
Example 1:

Input: root = [3,9,20,null,null,15,7]
Output: [[3],[9,20],[15,7]]


Example 2:

Input: root = [1]
Output: [[1]]


Example 3:

Input: root = []
Output: []


&nbsp;
Constraints:


	The number of nodes in the tree is in the range [0, 2000].
	-1000 &lt;= Node.val &lt;= 1000


# Definition for a binary tree node.
# class TreeNode:
#     def __init__(self, val=0, left=None, right=None):
#         self.val = val
#         self.left = left
#         self.right = right
class Solution:
    
        
    def levelOrder(self, root: Optional[TreeNode]) -> List[List[int]]:
        
        ret = []
        next_levels = [[root]]
        
        for level in next_levels:
            curr_lv = []
            next_lv = []
            for node in level:
                if not node: 
                    continue
                curr_lv.append(node.val)
                next_lv.append(node.left)
                next_lv.append(node.right)
            
            if curr_lv: 
                ret.append(curr_lv)
            if next_lv: 
                next_levels.append(next_lv)
        
        return ret
class Solution {
    public List<List<Integer>> levelOrder(TreeNode root) {
        List<List<Integer>> result = new ArrayList<>();
        if(root == null)
            return result;
        List<Integer> rootList = new ArrayList<>();
        rootList.add(root.val);
        result.add(rootList);
        levelOrder(root,1,result);
        return result;

    }

    private void levelOrder(TreeNode root, int level, List<List<Integer>> result) {
        if(root == null)
            return;
        List<Integer> children = exploreChildren(root);
        if(!children.isEmpty()){
            if(level < result.size())
                result.get(level).addAll(children);
            else
                result.add(children);
        }
        levelOrder(root.left, level + 1, result);
        levelOrder(root.right, level + 1,result);
    }

    private List<Integer> exploreChildren(TreeNode root) {
        List<Integer> children = new ArrayList<>();
        if(root.left != null)
            children.add(root.left.val);
        if(root.right != null)
            children.add(root.right.val);
        return children;
    }
}
class Solution {
public:
    vector<vector<int>> levelOrder(TreeNode* root) {
       queue<TreeNode *>q;
        vector<vector<int>> result;
        if(root==NULL) return result;
        q.push(root);
        q.push(NULL);
        vector<int>temp;
        while(!q.empty())
        {
            TreeNode *top = q.front();
            q.pop();
            if(top==NULL)
            {
                result.push_back(temp);
                temp.clear();
                if(!q.empty())
                {
                    q.push(NULL);
                    continue;
                }
                return result;               
            }
            else temp.push_back(top->val);                            
            
            if(top->left) q.push(top->left);                
               
            if(top->right) q.push(top->right);            
        }
        
        return result;
    }
};
var levelOrder = function(root) {
  const result = [];
  if (root == null) return result

  let lvl = 0;
  let temp = [];
  let q = new Queue();
  q.enqueue(root)

  while (!q.isEmpty()) {
    let levelSize = q.size();
    while (levelSize-- != 0) {
      let node = q.dequeue()
      temp.push(node.val)
      // enqueue both children first,
      // before looking at the next dequeued item
      if (node.left != null) q.enqueue(node.left);
      if (node.right != null) q.enqueue(node.right);
    }
    result.push(temp);
    temp = [];
    lvl +=1
  }

  return result
};
Binary Tree Level Order Traversal