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. 在Spring框架中获取连接池的四种方式

    1:DBCP数据源 DBCP类包位于 <SPRING_HOME>/lib/jakarta-commons/commons-dbcp.jar,DBCP是一个依赖Jakarta commons ...

  2. DBMS的四大特性

  3. jmeter设置代理

    JMeter设置Http代理对web或者app进行录制 一.录制web 1.首先保证JMeter的安装环境都正确.启动JMeter:在安装路径的bin目录下双击jmeter.bat (例如:D:\ap ...

  4. matlab实现一次性实现多个文件夹图片转化为.mat文件

    %这里是主函数:命名为readImg.m; clc;clear; %---read_image; filepath = 'G:\人脸重建\data\src_all\';%图片路径可以根据自己需要修改; ...

  5. MyBatis框架的文件配置

    第一步:log4j.properties的配置 原因:Mybatis的日志输出是依赖与log4j的,所以必须要配置 # Global logging configuration log4j.rootL ...

  6. mybatis学习:mybatis的环境搭建与入门

    一.mybatis的概述: mybatis是一个持久层框架,用java编写 它封装了jdbc操作的很多细节,使开发者只需要关注sql语句本身,而无需关注注册驱动,创建连接登繁杂过程 它使用了ORM思想 ...

  7. LA2965 Jurassic Remains

    Jurassic Remains https://vjudge.net/problem/UVALive-2965 Paleontologists in Siberia have recently fo ...

  8. 基于PHP的一种Cache回调与自动触发技术

    $s = microtime(true); for($i=0; $iaaa($array, $array, $array); $data = a::bbb($array, $array, $array ...

  9. web前端学习(四)JavaScript学习笔记部分(9)-- JavaScript面向对象详解

    1.认识面向对象 1.1.概念 1.一切事物皆是对象 2.对象具有封装和继承特性 3.信息隐藏(类的信息隐藏,包括属性和方法) <!DOCTYPE html> <html lang= ...

  10. MySQL:比较两个数据表不同部分

    简单比较 1.SELECT * FROM t2 WHERE id NOT IN (SELECT id FROM t1); 2.SELECT * FROM t2 WHERE NOT EXISTS(SEL ...