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 {
public ArrayList<ArrayList<Integer> > Print(TreeNode pRoot) {
Queue<TreeNode> queue=new LinkedList<>();
ArrayList<ArrayList<Integer>> result=new ArrayList<ArrayList<Integer>>();
if(pRoot==null){
return result;
}
queue.offer(pRoot);
int flag=0;
while(!queue.isEmpty()){
ArrayList<Integer> temp=new ArrayList<>();
int length=queue.size();
for(int i=0;i<length;++i){
temp.add(queue.peek().val);
TreeNode node=queue.poll();
if(node.left!=null){
queue.offer(node.left);
}
if(node.right!=null){
queue.offer(node.right);
}
}
if(flag%2==1){
Collections.reverse(temp);
}
result.add(new ArrayList<>(temp));
++flag;
}
return result;
}
}
11-27
701
10-12
567