Java Level Order Solution


#1

public class Solution {
public int solve(TreeNode A) {

    int count = 0;

     
    if(A == null) return 0;
    
    Queue<TreeNode> q = new LinkedList<TreeNode>();
    q.offer(A);
  
    while(!q.isEmpty()){
        TreeNode temp = q.poll();
        if(temp != null){
            // curr.add(temp.val);
            count ++;
        }
            if(temp.left != null){
                q.offer(temp.left);
            }
            if(temp.right != null){
                q.offer(temp.right);
            }
      
        
    }
    return count;
}

}