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.
Function Signature
def repeated_n_times(nums: list[int]) -> int:
Rules
-
The input always satisfies the properties above. Every value other than the repeated one appears exactly once, so the answer is unique.
Constraints
-
2 <= n <= 5000
-
len(nums) == 2 * n
-
0 <= nums[i] <= 10^4
-
nums
contains
n + 1
unique elements and one of them is repeated
n
times.
Examples
Input: nums = [1, 2, 3, 3]
Output: 3
Here n = 2. The element 3 appears 2 times in an array of length 4, while 1 and 2 appear once each.
Input: nums = [2, 1, 2, 5, 3, 2]
Output: 2
Here n = 3. The element 2 appears 3 times in an array of length 6, and 1, 5 and 3 appear once each.
Input: nums = [9, 5, 6, 9]
Output: 9
Here n = 2. The two copies of 9 sit at opposite ends of the array, so no two copies are adjacent.