remove duplicates in array using method [migrated]
Im trying to remove duplicates numbers from an array using method but, unfortunatly I could not solve it yet and this what I have done so far..
//method code
public static int[] removeDuplicates(int[] input){
int []r=new int[input.length];
for (int i = 0; i < input.length; i++) {
for (int j = 0; j < input.length; j++) {
if ((input[i]==input[j]) && (i != j)) {
return r;
}
}
}
return r;
}
Im trying to remove duplicates numbers from an array using method but, unfortunatly I could not solve it yet and this what I have done so far..
//method code
public static int[] removeDuplicates(int[] input){
int []r=new int[input.length];
for (int i = 0; i < input.length; i++) {
for (int j = 0; j < input.length; j++) {
if ((input[i]==input[j]) && (i != j)) {
return r;
}
}
}
return r;
}
No comments:
Post a Comment