/**
* 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-25 20:26:57 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)