LintCode Flip Bits 将整数A转换为B
来源:互联网 发布:mac开压缩包有广告 编辑:程序博客网 时间:2024/06/10 15:41
如果要将整数A转换为B,需要改变多少个bit位?
样例
如把31转换为14,需要改变2个bit位。
(31)10=(11111)2
(14)10=(01110)2
挑战
你能想出几种方法?
Determine the number of bits required to flip if you want to convert integer n to integer m.
Example
Given n = 31 (11111), m = 14 (01110), return 2.
Note
Both n and m are 32-bit integers.
class Solution { /** *@param a, b: Two integer *return: An integer */ public static int bitSwapRequired(int a, int b) { int c = a ^ b; int count = 0; if (c < 0) { count++; c = Integer.MIN_VALUE ^ c; } while(c != 0) { count += c%2; c = c/2; } return count; }}
0 0
- LintCode Flip Bits 将整数A转换为B
- lintcode | 将整数A转换为B, Flip Bits
- 181.Flip Bits-将整数A转换为B(容易题)
- Lintcode 将整数A转换为B
- LintCode 将整数A转换为B
- lintcode----将整数A转换为B
- LintCode:将整数A转换为B
- LintCode : 将整数A转换为B
- lintcode:将整数A转换为B
- 将整数A转换为B-LintCode
- lintcode:将整数A转换为B
- 比特位操作——Flip Bits(将整数A转化为B)
- LintCode解题笔记 - 将整数A转换为B
- lintcode-将整数A转换为B-181
- 将整数A转换为整数B
- 题目:将整数A转换为B
- 将整数A转换为B
- 将整数A转换为B
- Eclipse+PyDev+Django+Mysql搭建Python web开发环境
- MIME_TYPE总结
- Intent带参数跳转
- iOS开发之即时通讯之环信
- 被虐记 2 期末测试
- LintCode Flip Bits 将整数A转换为B
- heartbeat配置
- 2015国际癫痫关爱日 昆明军海作为西南地区唯一受邀医院与会
- Python模块常用的几种安装方式
- Object c中的alloc和init问题
- AndroidManifest.xml——grant-uri-permission
- Intellij Idea 常用快捷键
- hiho一下 欧拉路三
- pydev代码编辑助手