Unable to find error


#1

public class Solution {
public int[][] levelOrder(TreeNode A) {
Queue q=new LinkedList();
ArrayList<ArrayList> al=new ArrayList<ArrayList>();
if(A==null)
return null;
q.add(A);
while(!q.isEmpty())
{ int c=q.size();
ArrayList all=new ArrayList();
for(int j=0;j<c;j++)
{ TreeNode d=q.peek();
all.add(d.val);
if(d.left!=null)
q.add(d.left);
if(d.right!=null)
q.add(d.right);
q.poll();
}
al.add(all);
}
int ans[][]=new int[al.size()][];
for(int i=0;i<al.size();i++)
{ int n=al.get(i).size();
int dum[]=new int[n];
ArrayList z=new ArrayList();
z=al.get(i);
int j=0;
for(int y:z)
{
dum[j]=y;
j++;
}
ans[i]=dum;
}
return ans;
}
}