Flip Bits
2016-07-15 05:31
381 查看
Determine the number of bits required to flip if you want to convert integer n to integer m.
Notice
Both n and m are 32-bit integers.
Example
Given n =
Notice
Both n and m are 32-bit integers.
Example
Given n =
31(11111), m =
14(01110), return
2.
class Solution { /** *@param a, b: Two integer *return: An integer */ public static int bitSwapRequired(int a, int b) { // write your code here int diff = a ^ b; int count = 0; while (diff != 0) { count++; // remove the last 1 diff = diff & (diff - 1); // 这种方法很好。 } return count; } };
相关文章推荐
- Delete Digits
- mysql查询正在执行的进程
- android自定义9宫格图片视图
- 缅甸维加斯开户网址:nob211.com 咨询热线:18206945156
- keepalived 安装
- C++调用C静态库,出现undefined reference to “” 的问题
- 【日志7.14】
- 缅甸维加斯赌场开户
- os x1
- Wood Cut
- 增强的页面元素
- 表单验证
- HTML5的新的表单属性
- HTML5新的Input类型
- HTML5音频
- HTML5视频
- Android 联系人数据库表详解
- Leetcode Factorial Trailing Zeroes
- drag and drop(拖拽)
- Leetcode Excel Sheet Column Number