Lets say I have an array short int check[10] = {1,1,1,1,1,1,1,1,1};.
I want to check if all the element are the same.
I can't find the answer in stackoverflow nor google, but I've come across this code in C++.
bool aresame(int a[], int n)
{
int i;
unordered_map<int, int> m;
for (i = 0; i < n; i++)
{
m[a[i]]++;
}
if (m.size() == 1)
{
return true;
}
else
{
return false;
}
}
Adjust a bit, and the result is huge error.
My attempt is usingif's but that's very un-professional.
Might as well know, is there are any other ways to do it?