Remove Duplicate Element From Sorted Array

In order to remove duplicate element from sorted array we will be following bubble sort algorthim concept that is comparing two addjacent element with each other repeatedly.

Example

class Employee
{
public static void main(String args[])
{
int[] values = {1,2,2,3,4,4,5,5};
int size = values.length;

int[] temp = new int[size];
int j =0;

for(int i = 0;i<size-1;i++)
{
if(values[i] != values[i+1])
{
temp[j] = values[i];
j++;
}
}
temp[j++] = values[size-1];

for(int i=0;i<j;i++)
System.out.println(""+temp[i]);

}
}

Time Complexity: O(n)

Space Complexity: O(n)