标签:16px ace == 长度 开始 space solution log parameter
1 class Solution { 2 public: 3 // Parameters: 4 // numbers: an array of integers 5 // length: the length of array numbers 6 // duplication: (Output) the duplicated number in the array number 7 // Return value: true if the input is valid, and there are some duplications in the array number 8 // otherwise false 9 bool duplicate(int numbers[], int length, int* duplication) { 10 if(length <= 0) 11 return false; 12 for(int i=0;i<length;i++) 13 { 14 if(numbers[i] <0 || numbers[i]>length-1) 15 { 16 return false; 17 } 18 } 19 for(int i=0;i<length;i++) 20 { 21 while(numbers[i] != i) 22 { 23 if(numbers[i] == numbers[numbers[i]]) 24 { 25 *duplication = numbers[i]; 26 return true; 27 } 28 //交换 29 int temp = numbers[i]; 30 numbers[i] = numbers[temp]; 31 numbers[temp] = temp; 32 } 33 } 34 return false; 35 } 36 };
标签:16px ace == 长度 开始 space solution log parameter
原文地址:http://www.cnblogs.com/qqky/p/7084602.html