I've written a method that accepts as a parameter an unsorted linked list and removes any duplicates found. The following is my code:
Now, I'm wondering what is the more efficient way of doing this. If I'm not mistaken, this is O(n^2).
Thanks in advance!
public static<T> void remove(java.util.LinkedList<T> list)
{
for(int i = 0; i < list.size(); i++)
{
for(int j = i + 1; j < list.size(); j++)
{
if(list.get(i).equals(list.get(j)))
{
list.remove(j);
}
}
}
}
Now, I'm wondering what is the more efficient way of doing this. If I'm not mistaken, this is O(n^2).
Thanks in advance!