Minimum Depth of Binary Tree

/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode() {}
* TreeNode(int val) { this.val = val; }
* TreeNode(int val, TreeNode left, TreeNode right) {
* this.val = val;
* this.left = left;
* this.right = right;
* }
* }
*/
class Solution {

public int minDepth(TreeNode root) {

if(root==null){
return 0;
}

Queue<TreeNode> queue = new LinkedList<TreeNode>();

queue.add(root);

int level = 1;
int minDepth = 1000000000;

while(!queue.isEmpty()){

int size = queue.size();

for(int i=0;i<size;i++){
TreeNode node = queue.remove();

if(node!=null && node.left==null && node.right==null){
if(minDepth>level){
return level;
}

}else{
if(node.left!=null){
queue.add(node.left);
}
if(node.right!=null){
queue.add(node.right);
}
}

}
level ++;
}

return minDepth;
}

}