Leecode刷题day1:查找重复元素-python
Leecode刷题day1:查找重复元素-python1.题目2.排序法3.哈希表法:map4.集合set()去重
1.题目
2.排序法
思路:先对列表元素排序,比较排序后相邻两个元素是否相等,返回结果。
代码:
class Solution:
def containsDuplicate(self, nums):
'''
:type nums: List(int)
:rtype: bool
'''
nums.sort()
for i in range(1, len(nums)):
原创
2021-09-07 11:04:17 ·
245 阅读 ·
0 评论