0
点赞
收藏
分享

微信扫一扫

剑指offer03:数组中重复的数字

驚鴻飛雪 2022-05-23 阅读 39


剑指offer03:数组中重复的数字_时间复杂度

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


举报

相关推荐

0 条评论