def getDuplication(numbers, length):
if numbers == None or length == 0:
return False
start, end = 1, length - 1
while start <= end:
middle = int(start + (end - start)/2)
count = countrage(numbers, length, start, middle)
if start == end:
if count > 1:
return start
else:
print("无重复")
if count > (middle - start + 1):
end = middle
else:
start = middle + 1;
return False
def countrage(numbers, length, start, middle):
if numbers == None or length == 0:
return False
count = 0
for i in numbers:
if i >= start or i <= middle:
count+=1
return count
【整理】剑指offer——Python 面试题3_2:数组中重复的数字
最新推荐文章于 2020-07-11 11:11:32 发布