LeetCode solutions

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

Read the problem on LeetCode View on GitHub

Python

Accepted on LeetCode — runtime 9ms, memory 18.5MB, accepted 2026-01-02.

python
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.

cpp
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;
    }
};

Source