ArrayList<ArrayList > Print(TreeNode pRoot) {
ArrayList<ArrayList> arrayLists = new ArrayList<ArrayList>();
if (pRoot==null) {
return arrayLists;
}
Queue queue = new LinkedList();
queue.add(pRoot);
while (!queue.isEmpty()) {
ArrayList arrayList = new ArrayList();
int count = queue.size();
for (int i = 0; i < count; i++) {
if (queue.peek().left!=null) {
queue.add(queue.peek().left);
}
if (queue.peek().right!=null) {
queue.add(queue.peek().right);
}
arrayList.add(queue.poll().val);
}
arrayLists.add(arrayList);
}
return arrayLists;
}