方法一:通过排序,然后判断相邻的两个元素是否相等
代码:
def judgeDuplicated(array): array.sort() count=0 while count方法二:使用字典
代码:
def judgeRepeated(array): nums={} for i in array: if i not in nums: nums[i]=True else: return True return False方法三:使用集合set(set和其他方法一样,存储的数据都是无序不重复的数据),我们可以通过判断列表转元组之后的长度是否和原长度相等来实现
代码:
def judgeRepeatedThird(array): if len(set(array))==len(array): return False else: return True


