-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?

2
  • 1
    Can you share the code you've written so far and where you got stuck? Commented Jul 15, 2016 at 4:34
  • 1
    how to achieve this using Java? - write some code. Commented Jul 15, 2016 at 4:34

1 Answer 1

-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;
}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.