ArrayList<ArrayList<Integer> > Print(TreeNode pRoot) { if(pRoot==null){ return null; } ArrayList<ArrayList<Integer> > mutiLineList = new ArrayList<ArrayList<Integer> >(); ArrayList<Integer> lineList = new ArrayList<Integer>(); lineList.add(pRoot.val); Queue<TreeNode> queque1 = new Queue<TreeNode>();//是接口还是class Queue<TreeNode> queque2 = new Queue<TreeNode>(); queque1.add(pRoot); mutiLineList.add(lineList); while(!queque1.isEmpty()||!queque2.isEmpty()){ while(!queque1.isEmpty()){ ArrayList<Integer> lineList1 = new ArrayList<Integer>(); TreeNode treeNode1 = queque1.getFirst(); lineList.add(treeNode1.val); if(treeNode1.left!=null){ queque2.add(treeNode1.left); } if(treeNode1.right!=null){ queque2.add(treeNode1.right); } } mutiLineList.add(lineList1); while(!queque2.isEmpty()){ ArrayList<Integer> lineList2 = new ArrayList<Integer>(); TreeNode treeNode2 = queque2.getFirst(); lineList.add(treeNode2.val); if(treeNode2.left!=null){ queque1.add(treeNode2.left); } if(treeNode2.right!=null){ queque1.add(treeNode2.right); } } mutiLineList.add(lineList2); } return mutiLineList; }