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     }

 

posted @ 2018-09-03 11:06  山里的小勇子  阅读(111)  评论(0编辑  收藏  举报