题解:
class Solution:
def containsDuplicate(self, nums: List[int]) -> bool:
# 1.先排序
new_nums = sorted(nums)
# 2.定义一个flag,默认值为false
flag = False
# 3.遍历排过序的新列表,如果相邻元素有相同的,则flag置为true
for i in range(len(new_nums)-1):
if new_nums[i] == new_nums[i+1]:
flag = True
return flag