Given an array with a length of N, its elements are also in the range of [0 n-1] to determine whether it contains repeated elements.
# Include <stdio. h>
# Include <stdlib. h>
# Include <iostream>
# Include <string>
Using namespace STD;
Bool find_repeat (int * s, int Len)
{
Int max (s [0]), min (s [0]);
If (LEN = 0)
Return false;
For (INT I = 1; I <Len; I ++)
{
If (s [I]> MAX)
{
Max = s [I];
}
Else if (s [I] <min)
{
Min = s [I];
}
}
Int temp = max-min;
If (temp = 0)
{
Return true;
}
For (INT I = 0; I <Len; I ++)
{
S [I] = s [I]-min;
}
// Int I = 0;
For (INT I = 0; I <Len; I ++)
{
While (s [I]! = I)
{
If (s [s [I] = s [I])
Return true;
Else
{
Int temp = s [I];
S [I] = s [temp];
S [temp] = temp;
}
}
}
Return false;
}
Int main ()
{
Int A [] = {, 2 };
If (find_repeat (A, 7 ))
Cout <"Repeat true" <Endl;
Else
Cout <"no repeat" <Endl;
For (INT I = 0; I <7; I ++)
Cout <A [I] <"";
Cout <Endl;
Return 0;
}
Search for duplicate strings