def findDuplicate(self, nums):
for x in nums:
if nums[abs(x)-1] < 0:
nums[abs(x)-1] *= -1
Can you please explain the idea behind the code? Thanks.
@woshianderson It is using the number in nums as the index, if a number appears twice, then this nums[number] will be changed to negative number before.
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.