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

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,#,#,15,7},

    3
/ \
9  20
/  \
15   7


return its level order traversal as:

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

public static List<List<Integer>> levelOrder(TreeNode root) {

List<List<Integer>> result=new ArrayList<List<Integer>>();//返回的最终结果

//处理第一个节点（root）
if(root==null)
return result;
else {
List<Integer> temp=new ArrayList<>();//存放暂时的结果
treeNodes2.offer(root);

}

while(!treeNodes2.isEmpty())
{
int i=treeNodes2.size();
List<Integer> tempReslut=new ArrayList<>();//存放暂时的结果
while(i>0)//遍历这一层的所有节点
{

TreeNode tNode=treeNodes2.poll();
if(tNode.left!=null)
{
treeNodes2.offer(tNode.left);
}
if(tNode.right!=null)
{
treeNodes2.offer(tNode.right);
}
i--;
}
}

return result;

}

#### 【LeetCode-面试算法经典-Java实现】【103-Binary Tree Zigzag Level Order Traversal（二叉树分层Z字形遍历）】

2015-08-08 06:35:14

#### [leetcode-102]Binary Tree Level Order Traversal（java)

2015-08-11 11:28:30

#### leetcode 102 Binary Tree Level Order Traversal

2015-07-14 22:53:54

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

2014-01-15 06:44:39

#### LeetCode102: Binary Tree Level Order Traversal

2016-11-27 19:06:53

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

2018-03-19 19:28:31

#### LeetCode102——Binary Tree Level Order Traversal

2015-02-05 15:31:46

#### LeetCode 102:Binary Tree Level Order Traversal

2015-12-15 12:33:53

#### LeetCode102 Binary Tree Level Order Traversal Java

2016-04-23 14:20:55

#### 【LeetCode-面试算法经典-Java实现】【102-Binary Tree Level Order Traversal（二叉树层序遍历）】

2015-08-08 06:41:47

## 不良信息举报

LeetCode102 Binary Tree Level Order Traversal Java题解