//层次遍历 逆序
public class Solution {
public List<List<Integer>> levelOrderBottom(TreeNode root) {List<List<Integer>> llist=new ArrayList<List<Integer>>();
List<Integer> ilist=new ArrayList<Integer>();
if(root==null)
return llist;
Deque<TreeNode> queue= new LinkedList<TreeNode>();
TreeNode p;
int cur=1,next=0;
queue.addLast(root);
while(!queue.isEmpty()){
cur--;
p=queue.removeFirst();
ilist.add(p.val);
if(p.left!=null){
queue.addLast(p.left);
next++;
}
if(p.right!=null){
queue.addLast(p.right);
next++;
}
if(cur==0){
cur=next;
next=0;
llist.add(ilist);
ilist=new ArrayList<Integer>();
}
}
Collections.reverse(llist);
return llist;
}
}