public int minDepth(TreeNode root) {
        if(root==null){
            return 0;
        }
        LinkedList<TreeNode> queue = new LinkedList<TreeNode>();
        LinkedList<TreeNode> childQueue = new LinkedList<TreeNode>();
        queue.add(root);
        int depth = 1;
        while (!queue.isEmpty()){
            TreeNode node = queue.remove();
            if(node.left==null && node.right==null){
                return depth;
            }
            if(node.left!=null){
                childQueue.add(node.left);
            }
            if(node.right!=null){
                childQueue.add(node.right);
            }
            if(queue.isEmpty() && !childQueue.isEmpty()){
                depth++;
                queue.addAll(childQueue);
                childQueue.clear();
            }
        }
        return depth;
    }