bool IsHaveDup(int[] myArray, int arraySize)
{
int i, j;
bool isHaveDup = false;
for (i = 0; i < arraySize - 1; i++)
{
for (j = i + 1; j < arraySize; j++)
{
if (myArray[i] == myArray[j])
{
isHaveDup = true;
break;
}
}
if (isHaveDup)
{
break;
}
}
return isHaveDup;
}
The complexity is O(N^2) = N * ((N + 1)/2)
A better solution is to sort the array and then check for duplication then complexity is O(N*logN) for sorting and one quick loop on the array for duplication O(N) In total: O(N)+O(n*logN) = O(NlogN)