LeetCode 2015/3/22 Hammingweight
来源:互联网 发布:seo外包的优势 编辑:程序博客网 时间:2024/05/16 15:01
问题
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 ret = 0; if (n == 0) return 0; while (n != 1){ if (n % 2 == 1){ ret ++; } n /= 2; } return ++ret; }};
0 0
- LeetCode 2015/3/22 Hammingweight
- LeetCode 2015/3/22 Reverse Bits
- LeetCode #22
- leetcode 3
- LeetCode(3)
- LeetCode--3
- LeetCode(3)
- LeetCode-3*
- leetcode(3)
- LeetCode(3)
- leetcode 3
- LeetCode(3)
- LeetCode 2015/3/24 Rotate Array
- leetcode note--leetcode 16 3Sum Closest
- LeetCode 22: Generate Parentheses
- LeetCode(22)GenerateParentheses
- [leetcode 22] Valid Parentheses
- LeetCode 22 Surrounded Regions
- jackson时间格式处理
- 【龙书笔记】编译器内部实现流程初探
- c#在定义各种种类对象的时候分配内存的时机
- Java thread中对异常的处理策略
- 数据库设计以及mysql操作基础
- LeetCode 2015/3/22 Hammingweight
- 编译gdbserver和arm-linux-gdb
- Unit / Integration Testing the Bean Validation (JSR-303) 集成测试BEAN验证
- 1 Two Sum
- JVM虚拟机
- Android ActionBar完全解析(上)
- ddpush 学习之路 7 UDPClientBase.java
- 关于HTML网页源码的字符编码(charset)格式(GB2312,GBK,UTF-8,ISO8859-1等)的解释
- python里面的小知识【0】