LeedCode题目
思路:最简单的办法就是for循环,找到没有元素出现的个数,然后只要出现个数大于等于2,就return True,否则 return False.
语言:Python3
第一个阶段:
for i in range(len(nums)):
if nums.count(i)>=2:
return True
else:
return False
思路正确,可是测试用例多的时候回超出,所以有了第二个版本:
class Solution:
def containsDuplicate(self, nums):
"""
:type nums: List[int]
:rtype: bool
"""
if len(nums)!=len(set(nums)):
return True
else:
return False
现在就可以了,第一次通过有点开心,以后学习更多会更新更好的代码。