Nested List Weight Sum


My non recursive solution:
public class Solution {
public int depthSum(List<NestedInteger> nestedList) {
int ans = 0, depth = 1;
Queue<List<NestedInteger>> queue = new LinkedList<>();
queue.offer(nestedList);
queue.offer(null);
while(!queue.isEmpty()){
List<NestedInteger> t = queue.poll();
if(t == null){
depth ++;
if(!queue.isEmpty())
queue.offer(null);
continue;
}
for(NestedInteger n : t){
if(n.isInteger()){
ans = ans + depth * n.getInteger();
}else{
queue.offer(n.getList());
}
}
}
return ans;
}
}