题目描述
blablabla
样例
blablabla
算法1
字典 $O(n)$
class Solution(object):
def duplicateInArray(self,nums):
n = len(nums)
flag = {i:0 for i in range(n)}
ans = -1
for _ in nums:
if _ >= n or _ < 0:
return -1
for _ in nums:
if flag[_] != 0:
return _
else:
flag[_] = 1
return -1