Find the Repeated Number in an Array
Implement findDuplicateNumber
You're given an array
nums of n + 1 integers, where every value lies between 1 and n. Exactly one value repeats — it might show up more than twice — while every other value appears exactly once. Find and return the repeated value.
Example 1:
Input: nums = [5,2,4,3,1,4]
Output: 4
Example 2:
Input: nums = [3,1,1]
Output: 1
Example 3:
Input: nums = [6,1,2,3,4,5,6]
Output: 6
+ 5 hidden test cases run on Submit.
Constraints:
- ●
2 ≤ n ≤ 10⁵, where n + 1 = nums.length - ●
1 ≤ nums[i] ≤ n - ●
Exactly one value in nums repeats — it may appear more than twice — and every other value appears exactly once
nums =
[5, 2, 4, 3, 1, 4]