leetcodeOJ 191. Number of 1 Bits
来源:互联网 发布:java调用ie内核 编辑:程序博客网 时间:2024/06/08 18:21
Write a function that takes an unsigned integer and returns the number of ’1' bits it has (also known as the Hamming weight).
For example, the 32-bit integer ’11' has binary representation 00000000000000000000000000001011
, so the function should return 3.
比较简单,
class Solution {public: int hammingWeight(uint32_t n) { int ans = 0; while(n != 0){ if(n%2 == 1){ ans++; } n >>= 1; } return ans; }};
0 0
- leetcodeOJ 191. Number of 1 Bits
- 191.Number of 1 Bits
- 191.Number of 1 Bits
- 191. Number of 1 Bits
- 191. Number of 1 Bits
- 191. Number of 1 Bits
- 191. Number of 1 Bits
- 191. Number of 1 Bits
- 191. Number of 1 Bits
- 191. Number of 1 Bits
- 191. Number of 1 Bits
- 191. Number of 1 Bits
- 191. Number of 1 Bits
- 191. Number of 1 Bits
- 191. Number of 1 Bits
- 191. Number of 1 Bits
- 191. Number of 1 Bits
- 191. Number of 1 Bits
- 复杂链表的复制
- DAY_04 函数及变量等的复习
- 【JZOJ5037】【NOI2017模拟3.30】轮回
- HDU3308 LCIS
- remove和removeat之间的区别?
- leetcodeOJ 191. Number of 1 Bits
- 关于unity5.x破解不了问题2
- Oracle DG gap 手动同步
- 2017跟着小虎玩着去软考--趣味好玩解析2015年下半年信息系统项目管理师上午试题41-45题
- 时间复杂度O(n)空间复杂度O(1)打印二叉树前中后序
- 进程的管理
- 使用ag-grid的cellRenderer渲染单元格
- python简单爬虫
- DOM节点的删除