# 102. 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]
]


/**二叉树的bfs和队列个数，可分层处理到每一层的的节点。
* Definition for a binary tree node.
* 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) {
vector<vector<int> > outer;
vector<int> inner;
queue<TreeNode*> q;
if (root)
q.push(root);
else
return outer;
while (!q.empty())
{
int size=q.size();//当前队列的个数，用来将当前层的节点全从队列中移除。
inner.clear();
while (size-->0)
{
TreeNode* t=q.front();
q.pop();
inner.push_back(t->val);
if (t->left)
q.push(t->left);
if (t->right)
q.push(t->right);
}
outer.push_back(inner);
}
return outer;
}

};

#### 【LeetCode】102. Binary Tree Level Order Traversal 解题报告

2016-05-26 15:06:54

#### LeetCode102 Binary Tree Level Order Traversal Java

2016-04-23 14:20:55

#### 102. Binary Tree Level Order Traversal [easy] (Python)

2016-05-10 14:40:58

#### LeetCode(102)Binary Tree Level Order Traversal

2014-01-15 06:44:39

#### leetcode 102 Binary Tree Level Order Traversal

2015-07-14 22:53:54

#### 【LeetCode with Python】 Binary Tree Level Order Traversal

2014-07-06 14:12:36

#### [C++]LeetCode: 31 Binary Tree Level Order Traversal

2014-11-25 19:17:18

#### LeetCode102 Binary Tree Level Order Traversal Java题解

2015-07-06 21:13:28

#### Leetcode_102_Binary Tree Level Order Traversal

2014-12-14 21:29:33

#### [LeetCode] Binary Tree Level Order Traversal 二叉树层次遍历(DFS | BFS)

2015-09-11 02:20:37