class Solution {
public List<Double> averageOfLevels(TreeNode root) {
if(root==null)
return new ArrayList<Double>();
List<Double> l=new ArrayList<Double>();
Queue<TreeNode> queue=new LinkedList<>();
queue.offer(root);
while(!queue.isEmpty()){
int size=queue.size();
double temp=0.0;
for(int i=0;i<size;++i){
TreeNode node=queue.poll();
temp+=node.val;
if(node.left!=null){
queue.offer(node.left);
}
if(node.right!=null){
queue.offer(node.right);
}
}
l.add(temp/size);
}
return l;
}
}
08-26