# Binary Tree Level Order Traversal

Given a binary tree, return the level order traversal of its nodes’ values. (ie, from left to right, level by level).

For example:
Given binary tree `[3,9,20,null,null,15,7]`,

```    3
/ \
9  20
/  \
15   7
```

return its level order traversal as:

```[
[3],
[9,20],
[15,7]
]```

## Solution – Easy to understand

```/**
* Definition for a binary tree node.
* public class TreeNode {
*     public int val;
*     public TreeNode left;
*     public TreeNode right;
*     public TreeNode(int x) { val = x; }
* }
*/
public class Solution {
public IList<IList<int>> LevelOrder(TreeNode root) {
var result = new List<IList<int>>();
if(root == null)
return result;
Queue<TreeNode> q = new Queue<TreeNode>();
q.Enqueue(root);
while(q.Count > 0)
{
List<int> list = new List<int>();
int size = q.Count;
for(int i=0;i<size;i++)
{
TreeNode node = q.Dequeue();
list.Add(node.val);
if(node.left != null)
q.Enqueue(node.left);
if(node.right != null)
q.Enqueue(node.right);
}
result.Add(list);
}
return result;
}
}
```

Time Complexity: O(n)

Space Complexity: O(n)