Description: This program takes an integer array(with duplicates) as input and outputs an integer array(without duplicates). Here we will go through the logic before coding the actual program. So let us consider an integer array InputArray with below mentioned values.
InputArray - Values as below
In the above input array the numbers 4 and 5 are duplicated. i.e., 4 occur thrice and 5 occur twice. So here, to remove the duplicates we will copy the contents of this array into a new array and while we copy each number, we will omit the duplicate entries.
- Take an element from first array
- Before copying into the second array, check if that element is present in the second array.
- If it is already present then don't copy. Instead ignore that element and go for next element and follow step 1.
- If it is not present then copy that element into the second array and go to step 1.
for(int i =0, j=0; i<array1.length; i++)
for (int k=0; k<=j; k++)
isDuplicate = true;