Number of 1 Bits
来源:互联网 发布:项目数据分析公司排名 编辑:程序博客网 时间:2024/06/13 21:34
c++
class Solution {public: int hammingWeight(uint32_t n) { int count = 0; while (n != 0) { count += (n & 0x01); n = n >> 1; } return count; }};
python
class Solution(object): def hammingWeight(self, n): """ :type n: int :rtype: int """ bn = bin(n)[2:] return bn.count('1')
0 0
- Number of 1 Bits
- Number of 1 Bits
- Number of 1 Bits
- Number of 1 Bits
- Number of 1Bits
- Number of 1 Bits
- Number of 1 Bits
- Number of 1 Bits
- Number of 1 Bits
- Number of 1 Bits
- Number of 1 Bits
- Number of 1 Bits
- Number of 1 Bits
- Number of 1 Bits
- Number of 1 Bits
- Number of 1 Bits
- Number of 1 Bits
- Number of 1 Bits
- 二叉树的遍历(Tree Traversals)参考极客
- 【博财老师】油价首次收线50之上,实时策略跟进
- 个人感想
- 基础SSH注解方式配置(ST2.1,SP3.1H4.14,JAVAEE6.0 JAVASE1.7)
- mysql —— 分表分区
- Number of 1 Bits
- 制作Swift Framework
- java处理日期时间的方法
- android layout_weight讲解
- 工程里面NSLog的处理方法
- HDU 4770 Lights Against Dudely(暴力)
- Oracle数据库:下载与安装图解
- 提莫惨遭四名队友围殴
- Mac环境下React Native开发App环境搭建