338. Counting Bits
来源:互联网 发布:网络分销系统发展趋势 编辑:程序博客网 时间:2024/05/20 18:00
iven a non negative integer number num. For every numbers i in the range 0 ≤ i ≤ num calculate the number of 1's in their binary representation and return them as an array.
Example:
For num = 5
you should return [0,1,1,2,1,2]
.
由以前求i的二进制中1的个数方法得知,i的二进制比i&(i-1)多一个
class Solution {public:vector<int> countBits(int num) {vector<int> res(num + 1);res[0] = 0;for (int i = 1; i <= num; i++){res[i] = res[i&(i - 1)] + 1;}return res;}};
0 0
- [leetcode] 338. Counting Bits
- 338. Counting Bits
- leetcode 338. Counting Bits
- LeetCodeOJ:338. Counting Bits
- [LeetCode]338. Counting Bits
- LeetCode#338. Counting Bits
- 338. Counting Bits
- [LeetCode] 338. Counting Bits
- LeetCode 338. Counting Bits
- 338. Counting Bits
- [LeetCode]338. Counting Bits
- LeetCode-338. Counting Bits
- LeetCode *** 338. Counting Bits
- 338. Counting Bits
- (leetcode) 338. Counting Bits
- Swift 338. Counting Bits
- #leetcode#338. Counting Bits
- LeetCode 338. Counting Bits
- 罗马数字转换为int
- 证书的那些事情
- Struts登录验证(防止未登录进入)
- 前端基础5 表单
- 到处都是坑--getLong
- 338. Counting Bits
- 开源物理引擎Bullet Physics下载与安装
- RN学习
- k近邻(kNN)算法的Python实现(基于欧氏距离)
- 一片空白*3
- com.autonavi.amap.mapcore.MapCore.nativeNewInstance:(Ljava/lang/String;Ljava/lang/String;)J
- 在GET传参数中获取地址栏中传递的参数
- 在GET传参数中获取地址栏中传递的参数
- Eclipse创建JSF应用的两种方式http://blog.sina.com.cn/s/blog_9ed782ea0102vm9m.html