1001. N-Repeated Element in Size 2N Array
My accepted Python and C++ solution to LeetCode problem 1001, N-Repeated Element in Size 2N Array, running in 9ms.
- Difficulty: Easy
- C++
- Python
- Runtime 9ms
- Memory 18.5MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
Python
Accepted on LeetCode — runtime 9ms, memory 18.5MB, accepted 2026-01-02.
class Solution:
def repeatedNTimes(self, nums: List[int]) -> int:
return Counter(nums).most_common(1)[0][0]C++
Accepted on LeetCode — runtime 0ms, memory 28.6MB, accepted 2025-12-27.
class Solution {
public:
int repeatedNTimes(vector<int>& nums) {
unordered_set<int> seen;
for (int n : nums) {
if (seen.count(n)) return n;
seen.insert(n);
}
return -1;
}
};