import java.util.ArrayList;
import java.util.LinkedList;
/*
public class TreeNode {
int val = 0;
TreeNode left = null;
TreeNode right = null;
public TreeNode(int val) {
this.val = val;
}
}
*/
public class Solution {
ArrayList<ArrayList<Integer> > Print(TreeNode root) {
ArrayList<ArrayList<Integer>> ans = new ArrayList<>();
if(root == null) {
return ans;
}
LinkedList<TreeNode> queue = new LinkedList<>();
queue.addLast(root);
while(!queue.isEmpty()) {
int sz = queue.size();
ArrayList<Integer> lvl = new ArrayList<>();
for(int i = 0; i < sz; i++) {
TreeNode tmp = queue.removeFirst();
lvl.add(tmp.val);
if(tmp.left != null) queue.addLast(tmp.left);
if(tmp.right != null) queue.addLast(tmp.right);
}
ans.add(lvl);
}
return ans;
}
}