Depends on the information.
If you know a range of numbers, for example 1-1000, you can use a bit array.
Assume that the range a ... b
Make an array bit with bits (ba). initialize them to 0.
Scroll the array when you get to the number x, change the bit in the place of xa to 1.
If there is already 1 there, you have a duplicate.
time complexity: O (n)
space complexity: (ba) bits
source share