思路
采用哈希表,遍历
代码
class Solution(object):
def findRepeatNumber(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
dic = {}
for i in nums:
if i not in dic:
dic[i]= 0
else:
return i
代码:最后一次测试超时了
class Solution(object):
def findRepeatNumber(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
n = len(nums)
res = []
for i in range(n):
if nums[i] in res:
return nums[i]
else:
res.append(nums[i])
return None