LeetCode题解之Counting Bits

1、题目描述

2、问题分析

利用bitset.

3 代码

1 vector<int> countBits(int num) {
2         vector<int> v;
3         for(int i = 0; i <= num; i++){
4             bitset<32> b(i);
5             v.push_back( b.count() );
6         }
7         
8         return v;
9     }
pp
原文地址:https://www.cnblogs.com/wangxiaoyong/p/9577431.html