Java for LeetCode 191 Number of 1 Bits
2015-06-06 21:55
465 查看
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
解题思路:
JAVA实现如下:
For example, the 32-bit integer ’11' has binary representation
00000000000000000000000000001011, so the function should return 3.
解题思路:
JAVA实现如下:
public int hammingWeight(int n) { int res = 0; while(n!=0){ res += n & 1; n >>>= 1; } return res; }
相关文章推荐
- Java面向对象小记(2)
- Java初级笔记_1
- 使用Spring JdbcTemplate调用存储过程
- struts2中validator配置文件验证不起作用的问题解决办法、根源
- Java for LeetCode 190 Reverse Bits
- java 实现自定义链表
- eclipse 最近出错误Unhandled event loop exception Item not added
- Java for LeetCode 189 Rotate Array
- Struts-config.xml配置详解
- Java for LeetCode 188 Best Time to Buy and Sell Stock IV【HARD】
- struts2学习笔记(1)---JSP页面向Action类传递参数
- Spring Security调研记录【七】--核心模型与实现
- java基础--多线程
- java的clone用法
- java基础(十一)--- IO
- 终于Get到了Java8的Lambda表达式,记录。
- JavaEE 要懂的小事:二、图解 Cookie(小甜饼)
- JavaEE 要懂的小事:二、图解 Cookie(小甜饼)
- Spring与quartz集成后的定时任务工厂类
- 解析JDK、J2EE、J2SE、J2ME的区别