Skip to content

Files

Latest commit

7a7d3f2 · Oct 20, 2020

History

History

05.06.Convert Integer

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
Oct 20, 2020
Oct 20, 2020
Jun 21, 2020

English Version

题目描述

整数转换。编写一个函数,确定需要改变几个位才能将整数A转成整数B。

示例1:

 输入:A = 29 (或者0b11101), B = 15(或者0b01111)
 输出:2

示例2:

 输入:A = 1,B = 2
 输出:2

提示:

  1. A,B范围在[-2147483648, 2147483647]之间

解法

Python3

Java

class Solution {
    public int convertInteger(int A, int B) {
        return Integer.bitCount(A ^ B);
    }
}

...