Can Somebody please tell what is wrong in this code


#1

Here is the code:
int Solution::hammingDistance(const vector &A) {
long long int n=A.size();
int i,j,temp,count=0;
vector v;
long long int sum=0;
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
temp=A[i]^A[j];
while(temp>0)
{
v.push_back(temp%2);
temp=temp/2;
}
for(int k=0;k<v.size();k++)
{
if(v[i]==1)
count++;
}
sum+=count;
}
}
return (sum%1000000007);
}

I have just took the xor of the numbers in every pair and just added the count of 1’s to the sum.


#2

Your solution lack in terms of time complexity. This can be done in O(n), while your solution is taking O(n^2).