码迷,mamicode.com
首页 > 其他好文 > 详细

LeetCode题解之Counting Bits

时间:2018-09-03 12:02:21      阅读:132      评论:0      收藏:0      [点我收藏+]

标签:问题   tco   alt   代码   png   i++   code   bitset   count   

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     }

 

LeetCode题解之Counting Bits

标签:问题   tco   alt   代码   png   i++   code   bitset   count   

原文地址:https://www.cnblogs.com/wangxiaoyong/p/9577431.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!