在一個長度爲n的數組裏的全部數字都在0到n-1的範圍內。 數組中某些數字是重複的,但不知道有幾個數字是重複的。也不知道每一個數字重複幾回。請找出數組中任意一個重複的數字。 例如,若是輸入長度爲7的數組{2,3,1,0,2,5,3},那麼對應的輸出是第一個重複的數字2。python
時間限制:1秒;空間限制:32768K;本題知識點:數組數組
# -*- coding:utf-8 -*- class Solution: # 這裏要特別注意~找到任意重複的一個值並賦值到duplication[0] # 函數返回True/False def duplicate(self, numbers, duplication): # write code here for i in range(0,len(numbers)-1): for j in range(i+1,len(numbers)): if numbers[i] == numbers[j]: duplication[0] = numbers[i] return True return False