Below is the problem description and algorithm that I have written. Is there anything to be done to improve this algorithm?
Given an integer array of unknown size, containing only numbers between 0 and 30, write a function to return an integer array containing all of the duplicates.
int[] findDupes(int[] array) {
int[] found = new int[30];
int[] dupes = new int[30];
int dupesCount = 0;
for (int i = 0; i < array.length; i++) {
if (found[array[i]] <= 1) {
found[array[i]]++;
}else{
continue;
}
if(found[array[i]] > 1){
dupes[dupesCount++] = array[i];
if (dupesCount == 30)
break;
}
}
if (dupesCount == 0)
return new int[0];
return dupes;
}
Am assuming that the best case for running this algorithm would n or 30 whichever is lower and the worst case for running this algorithm is n, since I have to scan the entire array to find duplicates. Any comments?