1. 题目描述
2.代码
1 class Solution: 2 def containsDuplicate(self, nums: List[int]) -> bool: 3 dic = {} 4 for n in nums: 5 if n not in dic: 6 dic[n] = 1 7 else: 8 return True 9 return False
思路: 遍历数组, 并把数组元素和出现次数存入字典, 如果字典中已经存在了数组元素, 则直接返回True. 如果进行了一次遍历, 则直接返回False.