class Solution {
public:
vector<int> countBits(int n) {
vector<int> ret_pot (n + 1);
for(int i = 0; i <= n; i++){
if (i % 2) ret_pot[i] = ret_pot[i - 1] + 1;
else ret_pot[i] = ret_pot[i / 2];
};
return ret_pot;
}
};
leetcode338.比特位记数(c艹代码
最新推荐文章于 2024-09-04 17:52:55 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)