LeetCode 961, Easy. Topics: Array, Hash Table. View on LeetCode.
Generate this problem as a practice environment: tested reference solution, 18 parametrized pytest cases, and a playground notebook:
Problem
You are given an integer array nums with the following properties:
nums.length == 2 * n.
nums contains n + 1 unique values, n of which occur exactly once in the array.
- Exactly one element of
nums is repeated n times.
Return the element that is repeated n times.
Examples
Constraints
- 2 <= n <= 5000
- nums.length == 2 * n
- 0 <= nums[i] <= 10^4
- nums contains n + 1 unique elements and one of them is repeated exactly n times.
Follow-up: Can you solve it without a hash table, in O(1) extra space?
Solution
Reference implementation from solution.py on GitHub, full suite in test_solution.py:
Complexity
Last modified on September 7, 2026