Search Bhai

 

Visitors

Find a repeated integer in array of size n?

int DuplicatedNumber(int *a, int size)
{
map hash;
bool founddup = false;
for(int i=0; i 0)
{
founddup= true;
break;
}
else
hash[a[i]]++;
}

return founddup ? a[i] : -1; // return the duplicated value or -1 if not found
}

Your Ad Here