Solution: Find the Duplicate Number
Let's solve the Find the Duplicate Number problem using the the Fast and Slow pattern.
We'll cover the following...
Statement
Given an array of positive numbers, nums
, such that the values lie in the range , inclusive, and that there are numbers in the array, find and return the duplicate number present in nums
. There is only one repeated number in nums
, but it may appear more than once in the array.
Note: You cannot modify the given array
nums
. You have to solve the problem using only constant extra space.
Constraints:
nums.length
-
nums[i]
- All the integers in
nums
are unique except for one integer that will appear more than once.
Solution
Access this course and 1400+ top-rated courses and projects.