Flip Bits:

标签:位运算

题目:Determine the number of bits required to flip if you want to convert integer to integer m.

解题思路:

给出两个数字a和b,返回两个数字中需要转换的内容
这道题主要是考察位运算的几种操作:
1.首先使用异或运算来确定在哪些位置上两个数字的二进制位不一样的数字上都填上1,得到bit=a^b.
2. 之后在与1进行与运算,如果bit的最后一位是1那么就得到1,否则为0
3. 将bit向右移动一位,比如00001001 –> 00000100, 这样每次都能检查到最后一位是0或者是1
4.反复如上过程,直到bit为0;

参考代码:

LintCode刷题笔记--Flip Bits的更多相关文章

  1. LintCode刷题笔记-- Update Bits

    标签: 位运算 描述: Given two 32-bit numbers, N and M, and two bit positions, i and j. Write a method to set ...

  2. lintcode刷题笔记(一)

    最近开始刷lintcode,记录下自己的答案,数字即为lintcode题目号,语言为python3,坚持日拱一卒吧... (一). 回文字符窜问题(Palindrome problem) 627. L ...

  3. LintCode刷题笔记-- LongestCommonSquence

    标签:动态规划 题目描述: Given two strings, find the longest common subsequence (LCS). Your code should return ...

  4. LintCode刷题笔记-- PaintHouse 1&2

    标签: 动态规划 题目描述: There are a row of n houses, each house can be painted with one of the k colors. The ...

  5. LintCode刷题笔记-- Maximum Product Subarray

    标签: 动态规划 描述: Find the contiguous subarray within an array (containing at least one number) which has ...

  6. LintCode刷题笔记-- Maximal Square

    标签:动态规划 题目描述: Given a 2D binary matrix filled with 0's and 1's, find the largest square containing a ...

  7. LintCode刷题笔记-- Edit distance

    标签:动态规划 描述: Given two words word1 and word2, find the minimum number of steps required to convert wo ...

  8. LintCode刷题笔记-- Distinct Subsequences

    标签:动态规划 题目描述: Given a string S and a string T, count the number of distinct subsequences of T in S. ...

  9. LintCode刷题笔记-- BackpackIV

    标签: 动态规划 描述: Given an integer array nums with all positive numbers and no duplicates, find the numbe ...

随机推荐

  1. Linux CentOS6.5安装Nginx1.8.0

    一. 安装nginx 1. 准备1.8.0安装包 nginx-1.8.0.tar.gz 2. 安装第三方依赖 yum install gcc-c++ yum install -y pcre pcre- ...

  2. Odoo加载机制指导流程

    Odoo的启动通过openerp-server脚本完成,它是系统的入口. 然后加载配置文件openerp-server.conf 或者 openerp_serverrc: openerp-server ...

  3. leetcode 1071 Greatest Common Divisor of Strings

    lc1071 Greatest Common Divisor of Strings 找两个字符串的最长公共子串 假设:str1.length > str2.length 因为是公共子串,所以st ...

  4. mapreduce.Job: Running job: job_1553100392548_0001

    这几天一直在尝试一个mapreduce的例子,但是一直都是卡在mapreduce.Job: Running job: job_1553100392548_0001,查看日志也不报错,查看每个配置文件没 ...

  5. springcloud:Eureka的使用

    1.认识Eureka 服务的管理. 问题分析 在刚才的案例中,itcast-service-provider对外提供服务,需要对外暴露自己的地址.而consumer(调用者)需要记录服务提供者的地址. ...

  6. 1858: [Scoi2010]序列操作

    1858: [Scoi2010]序列操作 Time Limit: 10 Sec Memory Limit: 64 MB Submit: 3397 Solved: 1624 [Submit][Statu ...

  7. 珂朵莉树(ODT)笔记

    珂朵莉树,又叫老司机树($Old\, Driver \, Tree$) 是一种暴力出奇迹,就怕数据不随机的数据结构. 适用 需要用线段树维护一些区间修改的信息…… 像是区间赋值(主要),区间加…… 原 ...

  8. 英特尔人工智能圆桌论坛举行 四位大咖论道AI

    英特尔人工智能圆桌论坛举行 四位大咖论道AI 2017-04-01 17:57     北京2017年4月1日电 /美通社/ -- 毫无疑问,人工智能已是最具变革力的发展趋势之一,在3月31日举行的2 ...

  9. LintCode 合并两个排序

    将两个排序链表合并为一个新的排序链表 样例 给出 1->3->8->11->15->null,2->null, 返回1->2->3->8-> ...

  10. 【springmvc学习】常用注解总结

    @Controller 在springmvc中,我们用它来告诉前端控制器,他这个类是controller,也就是springmvc的一个对象了,我们在spring.xml配置文件中用<conte ...