lintcode-easy-Flip Bits
2016-02-24 18:28
295 查看
Determine the number of bits required to flip if you want to convert integer n to integer m.
Example
Given n =
Note
Both n and m are 32-bit integers.
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) { // write your code here int count = 0; for(int i = 0; i < 32; i++){ int num1 = (a >> i) & 1; int num2 = (b >> i) & 1; if(num1 != num2) count++; } return count; } };
相关文章推荐
- codeforces 622E. Ants in Leaves
- 多线程——Java中继承Thread类与实现Runnable接口的区别
- Android的一些设计思想(201603)
- Lombok 安装、入门 - 消除冗长的 java 代码
- ios 如何通过XIB 或者storyboard 创建headView 和footerView?
- 模型选择准则之AIC和BIC
- 一个python 服务器程序性能分析
- activity生命周期
- Spring Annotation方式读取注入properties属性值
- mysql 基本使用
- 【Mac上的问题】ValueError: unknown locale: UTF-8
- lintcode-easy-Flatten Binary Tree to Linked List
- AIDL
- 欢迎使用CSDN-markdown编辑器
- springmvc集成Quartz
- java事件处理机制(自定义事件)
- leetcode 14. Longest Common Prefix
- bindService
- Python入门——1
- 3673: 可持久化并查集 by zky 主席树 可持久化数组