-1

I have an integer array sorted in descending order, and I have to remove duplicate elements and return remaining values from the array (without using java Collections).

ex:This is my array,

int a[]={12,12,8,6,4,4,2,1}

and The o/p should be,

{8,6,2,1}

how to achieve this using Java?

alok shreevathsa
  • 49
  • 2
  • 2
  • 11

1 Answers1

-2

here's the code

public static int[] removeDuplicates(int []s){
    int result[] = new int[s.length], j=0;
    for (int i : s) {
        if(!isExists(result, i))
            result[j++] = i;
    }
    return result;
}
private static boolean isExists(int[] array, int value){
    for (int i : array) {
        if(i==value)
            return true;
    }
    return false;
}