1.自己写:把每一个数拿出来和后面的数挨个对比,时间复杂度n^2
class Solution(object):
def findDuplicates(self, nums):
"""
:type nums: List[int]
:rtype: List[int]
"""
j = 0
k = 0
n = len(nums)
duplication =[]
while j < n-1:
for i in range(j+1,n):
if nums[j] == nums[i]:
duplication.append(nums[j])
k += 1
break
j += 1
return duplication