Use a hash set to track numbers seen so far.
Iterate through the array. If the current number is already in the set, a duplicate exists. Otherwise add it to the set.
A set provides O(1) average membership checks, so the first repeated value is detected immediately.
Use a hash set to track numbers seen so far.
Iterate through the array. If the current number is already in the set, a duplicate exists. Otherwise add it to the set.
A set provides O(1) average membership checks, so the first repeated value is detected immediately.