Find the Duplicate Number
Find the one repeated value without changing the array or using extra memory.
The problem
Implement Solution.findDuplicate(nums). nums holds n + 1 integers, where n is between 1 and 100,000, and every value is between 1 and n. Exactly one value is repeated, possibly more than twice. Return that value. Do not change nums, and use only O(1) extra space, so a set or a sorted copy is not allowed.
Starter code
class Solution:
def findDuplicate(self, nums):
passPublic examples
nums = [1, 3, 4, 2, 2]gives2nums = [1, 1]gives1nums = [3, 3, 3, 3]gives3
Solving it in the practice book needs an active paid plan.
Open it in the practice bookOne thought at a time.
