find Duplicate numbers in array

how i can find Duplicate numbers in array? (c++).

There are multiple ways.

First, you surely know how to find a value from a range?

You can take any element from the array and use the "find" above to check whether the rest of the array has same value. If you do repeat this for each element from begin to second to last, you will gather the repeating values.


Alternatively, you could sort the array elements to ascending order. If there are any duplicate values, they will be in consecutive elements after the sort.


You could create a "table" -- list of "key", "value" pairs, where the keys are the unique values in your array and the values are counts of each value. If a value is unique -- occurs only once in the array -- then the table has value 1 for it and if a value occurs more than once, then the value is larger than 1.
Topic archived. No new replies allowed.