Inscrivez-vous ou connectez-vous pour rejoindre votre communauté professionnelle.
public class FindMissingNumberInSortedArrayExample
{
static int ar[]={3,5,8,}; //given array
public static void main(String[] args)
{
displayMissing();
}
/* * Method finds out missing number in given range. */
static public void displayMissing()
{
System.out.print("given array(already sorted): ");
for (int j =0; j < ar.length; j++)
System.out.print(ar[j] +" "); // display it
System.out.print("\\nNumbers missing between1 to in array : ");
int j=0;
for(int i=1;i<=;i++)
{
if(j<ar.length && i==ar[j])
j++;
else
System.out.print(i+" ");
}
}
}
Sort the array first then check the next number is old one + 1