LeetCode 338. Counting Bits
来源:互联网 发布:linux 双系统安装 编辑:程序博客网 时间:2024/04/25 20:23
1的个数可以归纳为,num/2 中的 1的个数 加上 num%2中 1 的个数
class Solution {public: vector<int> countBits(int num) { vector<int> vec; if(num == 0) vec.push_back(0); if(num == 1) {vec.push_back(0);vec.push_back(1);} else { vec.resize(num+1); vec[1] = vec[2] = 1; for(int i =3 ;i<=num;i++) vec[i] = vec[i/2] + vec[i%2]; } return vec; }};
0 0
- [leetcode] 338. Counting Bits
- leetcode 338. Counting Bits
- [LeetCode]338. Counting Bits
- LeetCode#338. Counting Bits
- [LeetCode] 338. Counting Bits
- LeetCode 338. Counting Bits
- [LeetCode]338. Counting Bits
- LeetCode-338. Counting Bits
- LeetCode *** 338. Counting Bits
- (leetcode) 338. Counting Bits
- #leetcode#338. Counting Bits
- LeetCode 338. Counting Bits
- leetcode 338. Counting Bits
- LeetCode-338. Counting Bits
- LeetCode-338. Counting Bits
- leetcode-338. Counting Bits
- Leetcode 338. Counting Bits
- LeetCode 338. Counting Bits
- Bi-shoe and Phi-shoe(欧拉函数变形)
- Android多线程下载断点续传
- 面向切面编程 Aspect Oriented Programming
- android常用UI控件总结
- bzoj 3820: 虫逢 hash
- LeetCode 338. Counting Bits
- Python常见问题(1):来历与简介General Python FAQ
- int main(int argc,char* argv[])浅析
- C++ 常量指针 指向常量的指针
- AOP那点事儿:面向切面编程(1)
- Python常见问题(2):编程问题 Programming FAQ
- Qt中Ui名字空间以及setupUi函数的原理和实现
- Effective C++ 3e----new & delete(八)条款50:了解new和delete的合理替换时机
- Struts2在打包json格式的懒加载异常问题