Leetcode-191. Number of 1 Bits
来源:互联网 发布:php跳转页面 编辑:程序博客网 时间:2024/04/30 01:22
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.
Credits:
Special thanks to @ts for adding this problem and creating all test cases.
Subscribe to see which companies asked this question
写一个函数 返回一个无符号整形数中“1”的数量;
比如32位整数11的二进制数为00000000000000000000000000001011;函数输出3;
public class Solution { public static int hammingWeight(int n) { String s = Integer.toBinaryString(n).toString().trim(); int m = 0; for(int i = 0 ; i < s.length(); i++){ if("1".equals(s.substring(i, i+1))){ m += 1; } } return m; }}
0 0
- 191. Number of 1 Bits Leetcode Python
- 【LeetCode】191.Number of 1 Bits
- [LeetCode]191.Number of 1 Bits
- LeetCode 191. Number of 1 Bits
- LeetCode 191. Number of 1 Bits
- [leetcode] 191. Number of 1 Bits
- <LeetCode OJ> 191. Number of 1 Bits
- Leetcode 191. Number of 1 Bits
- leetCode 191. Number of 1 Bits
- 191. Number of 1 Bits LeetCode
- Leetcode: 191. Number of 1 Bits(JAVA)
- LeetCode 191. Number of 1 Bits
- [LeetCode]191. Number of 1 Bits
- leetcode 191. Number of 1 Bits
- LeetCode *** 191. Number of 1 Bits
- [LeetCode]191. Number of 1 Bits
- LeetCode 191. Number of 1 Bits
- leetcode-191. Number of 1 Bits
- java 基础类库(IO,集合类,线程)
- CodeForces-16A-Flag
- 死锁的三种形式:一般死锁,嵌套管程锁死,重入锁死
- iOS应用内跳转系统设置相关界面的方法
- 【C++ 学习】03 做个遵纪守法的码农
- Leetcode-191. Number of 1 Bits
- 开发 JAVA 的准备
- 给大家推荐一个神奇的文献搜索网站sci-hub
- ajax跨域请求简单实现Java后台
- 看见的力量 – (II) 影响地图
- leetcode-25-Reverse Nodes in k-Group
- CodeForces-17A-Noldbach problem
- PHP检测url重定向的最终地址
- 文章标题