#961
Easy Algorithms N repeated element in size 2n array
Array Hash Table
79.8% acceptance
Feb 25, 2026
1848
348
You are given an integer array nums with the following properties:
nums.length == 2 * n.
nums contains n + 1 unique elements.
Exactly one element of nums is repeated n times.
Return the element that is repeated n times.
Solution
Rust
Time O(n)
Space O(n)
impl Solution {
pub fn repeated_n_times(nums: Vec<i32>) -> i32 {
let mut seen = std::collections::HashSet::new();
for x in nums {
if !seen.insert(x) { return x; }
}
unreachable!()
}
}