Find the Duplicate Number
Find the Duplicate Number
Given an array of integers nums containing n + 1 integers where each integer is in the range [1, n] inclusive, there is only one repeated number in nums. Return this repeated number.
You must solve it without modifying the array nums and using only constant extra space.
Examples
Example 1:
Input: nums = [1, 3, 4, 2, 2]
Output: 2Example 2:
Input: nums = [3, 1, 3, 4, 2]
Output: 3Example 3:
Input: nums = [3, 3, 3, 3, 3]
Output: 3Constraints
1 <= n <= 10^5nums.length == n + 11 <= nums[i] <= n- There is only one repeated number in
nums, but it could be repeated more than once.
Expected Complexity
- Time: O(n)
- Space: O(1)
MEDIUM
Singly Linked List
Fast/Slow Pointers
Cycle Detection
Intermediate
0 views
Solution
Hints
Hint 1
Hint 2
Premium
Hint 3
Premium
Hint 4
Premium
This section is available for CodeSnatch Premium members only.
