I having a problem with coding this:
Write a static method named removeDuplicates
that takes as input an array of integers and returns as a result a new array of integers with all duplicates removed.
For example, if the input array has the elements {4, 3, 3, 4, 5, 2, 4} the resulting array
should be {4, 3, 5, 2}
Here's what I have done so far
public static int[] removeDuplicates(int []s){
int [] k = new int[s.length];
k[0]=s[0];
int m =1;
for(int i=1;i<s.length;++i){
if(s[i]!=s[i-1]){
k[m]=s[i];
++m;
}//endIF
}//endFori
return k;
}//endMethod
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…