Can someone tell whats wrong


#1

int Solution::cntBits(vector &A) {
vectortemp(A.size());
int res=0;
for(int i=0;i<A.size();i++)
{
if(A[i]==0) { temp[i]=“0”; break; }
while(A[i]>0)
{
temp[i]=to_string(A[i]%2)+temp[i];
A[i]=A[i]/2;
}
}
int maxi=temp[0].length();
for(int i=1;i<temp.size();i++)
{
if(temp[i].length()>maxi) maxi=temp[i].length();
}
int x=0;
for(int i=0;i<temp.size();i++)
{
x=maxi-temp[i].length();
while(x>0)
{ temp[i]=“0”+temp[i]; x–; }
}
int n1=0,n2=0;
for(int i=0;i<maxi;i++)
{
for(int j=0;j<temp.size();j++)
{
if(temp[j][i]==‘0’) n1++;
else if(temp[j][i]==‘1’) n2++;
}
res+=(2n1n2);n1=0;n2=0;
}
return res;
}