public int minDepth(TreeNode root) {
        int depth = 0;
        if (root == null) {
            return depth;
        }

        Queue<TreeNode> queue = new LinkedList<TreeNode>();
        queue.offer(root);

        while (!queue.isEmpty()) {
            depth++;
            Queue<TreeNode> subQueue = new LinkedList<TreeNode>();
            while (!queue.isEmpty()) {
                TreeNode t = queue.poll();
                if (t.left != null) {
                    subQueue.offer(t.left);
                }

                if (t.right != null) {
                    subQueue.offer(t.right);
                }

                if (t.left == null && t.right == null) {
                    return depth;
                }
            }
            queue.addAll(subQueue);
        }
        return depth;
    }