与AcWing 13. 找出数组中重复的数字类似,用hash表
class Solution(object):
def duplicateInArray(self, nums):
"""
:type nums: List[int]
:rtype int
"""
n=len(nums)
hash_table = [0 for x in range(0,n+1)]
for i in nums:
hash_table[i]+=1
if hash_table[i]>1:
return i
return -1
有没有空间O(1)的做法?
o1的做法,看y总的代码