https://leetcode-cn.com/problems/binary-tree-level-order-traversal/
class Solution {
public List<List<Integer>> levelOrder(TreeNode root) {
if(root==null) return new ArrayList<List<Integer>>();
List<List<Integer>> ans = new ArrayList<>();
Deque<TreeNode> queue = new LinkedList<>();
queue.add(root);
while (!queue.isEmpty()){
int currentSize = queue.size();
List<Integer> list = new ArrayList<>();
for(int i=0;i<currentSize;i++){
TreeNode temp = queue.pop();
list.add(temp.val);
if(temp.left!=null){
queue.offer(temp.left);
}
if(temp.right!=null){
queue.offer(temp.right);
}
}
ans.add(list);
}
return ans;
}
}