import java.util.*; /* 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 pRoot) { Queue<TreeNode> que = new LinkedList<TreeNode>(); ArrayList<ArrayList<Integer>> res = new ArrayList<>(); if(pRoot==null) return res; que.offer(pRoot); while(!que.isEmpty()){ int n = que.size(); ArrayList<Integer> temp = new ArrayList<>(); for(int i=0;i<n;i++){ TreeNode cur = que.poll(); temp.add(cur.val); if(cur.left!=null) que.offer(cur.left); if(cur.right!=null) que.offer(cur.right); } res.add(temp); } return res; } }