leetcode第217题,寻找重复元素,只要存在重复元素就返回True。
这个题就很简单了,直接用hash就可以了,没什么难度。
class Solution(object):
def containsDuplicate(self, nums):
"""
:type nums: List[int]
:rtype: bool
"""
d = {}
n = len(nums)
for i in range(n):
if nums[i] not in d:
d[nums[i]] = i
else:
return True
return False