From ad3e5e9f23ff9c32f4e8b5a8ce66e02ae5088629 Mon Sep 17 00:00:00 2001 From: clxchen <37133855+clxchen@users.noreply.github.com> Date: Wed, 7 Mar 2018 18:26:47 +0800 Subject: [PATCH] Update InterviewTest3.cpp --- InterviewTest3.cpp | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/InterviewTest3.cpp b/InterviewTest3.cpp index e61ef7b..bc183c9 100644 --- a/InterviewTest3.cpp +++ b/InterviewTest3.cpp @@ -1 +1,25 @@ -aa +//for finding the duplicate number + +bool duplicate(int numbers[],int length, int* duplication) +{ + if(numbers == nullptr || length <=0) + return false; + for(int i = 0; i < length;++i) + { + if(numbers[i] < 0 || numbers[i] >length - 1) + return false; + } + for(int i = 0; i< length ; ++i) + { + while(numbers[i] != i) + { + if( numbers[i] = numbers[numbers[i]]) + return true; + //交换两数 + int temp = numbers[i]; + numbers[i] = numbers[temp]; + numbers[temp] = temp; + } + } +} +