题目
Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the array, and it should return false if every element is distinct.
代码
class Solution(object):
def containsDuplicate(self, nums):
"""
:type nums: List[int]
:rtype: bool
"""
if nums==None or len(nums)==0:
return False
unique_nums = set()
for n in nums:
if n in unique_nums:
return True
else:
unique_nums.add(n)
return False
网友评论