Blogger

Delete comment from: Javarevisited

Satishkumar said...

public class MissingNumbersExample {

public static void main(String[] args) {
int[] arr = {1, 3, 4, 5, 7, 10};
missingNumber(arr, 10);
}
// if the array is an sorted array simple way to find missing numbers as follow
public static void missingNumber(int[] array, int count) {
int[] mn=new int[count-array.length];
int n=0;
int j = 1;
for (int i = 0; i < 10; i++) {
if (i < array.length) {
if (array[i] != j) {
mn[n]=j;
n++;
i--;
}
}
j++;
}
System.out.println("Missing numbers :"+Arrays.toString(mn));
}
}

Jan 11, 2020, 11:20:17 AM


Posted to How to Find Missing Number on Integer Array of 1 to 100 - BitSet Example

Google apps
Main menu