/**
* Note: The returned array must be malloced, assume caller calls free().
*/
int good1(int n)
{
int count=0;
while(n>0)
{
count=count+n%2;
n=n/2;
}
return count;
}
int* countBits(int n, int* returnSize) {
int*good=(int*)malloc(sizeof(int)*(n+1));
*returnSize=n+1;
for(int x=0;x<=n;x++)
{
good[x]=good1(x);
}
return good;
}
力扣相同题:比特位计数
最新推荐文章于 2024-07-30 20:50:32 发布