vector<int> countBits(int num) {
vector<int> res(num+1, 0);
int i = 1;
int x = 0;
while (i <= num) {
while (i <= num && pow(2, x) <= i && i < pow(2, x + 1))
{
res[i] = 1 + res[i - pow(2, x)];
i++;
}
x++;
}
return res;
}
338. Counting Bits
最新推荐文章于 2022-05-28 13:29:42 发布