import math
class Solution(object):
def findDuplicate(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
for num in nums:
if nums[abs(num)] < 0:
return abs(num)
else:
nums[abs(num)] *= 1
Shortest Solution with O(N) time and O(1) space complexity

@HenryGau Probably because the very first note clearly says "You must not modify the array" (emphasis not mine). So this is obviously not an ok solution.


@ufarooqi said in Shortest Solution with O(N) time and O(1) space complexity:
Because you can not change the array