public int minDepth(TreeNode root) {
        int minDepth = 0;

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

        ArrayList<TreeNode> current = new ArrayList<TreeNode>();
        ArrayList<TreeNode> next = new ArrayList<TreeNode>();

        current.add(root);

        while (!current.isEmpty()) {
            //check one by one
            TreeNode node = current.get(0);
            current.remove(0);

            if (node != null) {
                //if no left and right node, it is the end of the path
                if (node.getLeft() == null && node.getRight() == null) {
                    return minDepth++;
                }

                //add left and right into the check list
                next.add(node.getLeft());
                next.add(node.getRight());
            }

            //the nodes of current level have been checked. go down one level
            //clone the next level to current level, and clear next level
            if (current.isEmpty()) {
                minDepth++;
                current = (ArrayList<TreeNode>) next.clone();
                next.clear();
            }
        }
        return minDepth;
    }