Title Description: All numbers in an array of length n are within the range of 0 to n-1. Some of the numbers in the array are duplicates, but it is not known that several numbers are duplicates. I don't know how many times each number repeats. Please find any duplicate numbers in the array. For example, if you enter an array of length 7 {2,3,1,0,2,5,3}, the corresponding output is the first repeating number 2.
AC Code:
1 Public classSolution {2 //Parameters:3 //numbers:an array of integers4 //length:the length of array numbers5 //duplication: (Output) The duplicated number in the array number,length of duplication array is 1,so using Duplicat Ion[0] =? in implementation;6 //Here duplication-like Pointor-C + +, duplication[0] equal *duplication in C/C + +7 //here to pay special attention ~ return any duplicate one, assignment value duplication[0]8 //Return Value:true If the input is valid, and there be some duplications in the array number9 //otherwise falseTen Public BooleanDuplicateintNumbers[],intLengthint[] duplication) { One ints[]=New int[length]; A for(inti=0;i<length;i++){ -s[numbers[i]]++; - if(s[numbers[i]]>1){ theduplication[0]=Numbers[i]; - return true; - } - } + return false; - } +}
A sword is a repeating number in a offer-array.