# 二叉树的层序遍历

<p>给你一个二叉树，请你返回其按 <strong>层序遍历</strong> 得到的节点值。 （即逐层地，从左到右访问所有节点）。</p>

<p> </p>

<p><strong>示例：</strong><br />
二叉树：<code>[3,9,20,null,null,15,7]</code>,</p>

<pre>
    3
   / \
  9  20
    /  \
   15   7
</pre>

<p>返回其层序遍历结果：</p>

<pre>
[
  [3],
  [9,20],
  [15,7]
]
</pre>


## template

```cpp
#include <bits/stdc++.h>
using namespace std;

struct TreeNode
{
    int val;
    TreeNode *left;
    TreeNode *right;
    TreeNode(int x) : val(x), left(NULL), right(NULL) {}
};


class Solution
{
public:
    vector<vector<int>> levelOrder(TreeNode *root)
    {
        if (root == NULL)
            return {};
        queue<TreeNode *> queue;
        TreeNode *p = root;
        vector<vector<int>> res;
        queue.push(p);
        while (queue.empty() == false)
        {
            vector<int> temp = {};
            int length = queue.size();
            for (int i = 0; i < length; i++)
            {
                p = queue.front();
                queue.pop();
                temp.push_back(p->val);
                if (p->left)
                    queue.push(p->left);
                if (p->right)
                    queue.push(p->right);
            }
            res.push_back(temp);
        }
        return res;
    }
};

```

## 答案

```cpp

```

## 选项

### A

```cpp

```

### B

```cpp

```

### C

```cpp

```