There are several different ways to detect / remove duplicates:
Nested loops
Follow the next value sequentially, then scan to the end of the list to see if this value is again. This is O (n 2 ) - although I believe that the boundaries can be stated below? - but the actual performance may be better since only scanning from i to end (not from 0 to end ) is performed, and it may end earlier. This does not require additional data, except for a few variables.
(See Christophe on how to do this simply by going around the linked list and destructively adding to the new list — for example, nested loops should not “feel” like nested loops.)
Sort and filter
Sort the list (mergesort can be modified to work with linked lists) and then detect duplicate values (they will now be side by side). With good sorting, this is O (n * lg (n)). The sorting phase is usually / can be destructive (for example, you have a “single copy”), but it has been changed; -)
Scan and support search
Scan the list, and when scanning the list, add values to search. If the search already contains the specified values, then there is a duplicate! This approach can be O (n) if access to the search is O (1). Usually, a hash / dictionary or set is used as the search, but if only a limited range of integrals is used, the array will work very well (for example, the index is a value). This requires additional storage, but there is no “additional copy” - at least in literal reading.
For small values of n, large-0 is almost useless; -)
Happy coding.
user166390
source share