leetcode/lcci/05.06.Convert Integer
..
README.md
README_EN.md
Solution.java

README_EN.md

05.06. Convert Integer

中文文档

Description

Write a function to determine the number of bits you would need to flip to convert integer A to integer B.

Example1:


 Input: A = 29 (0b11101), B = 15 (0b01111)

 Output: 2

Example2:


 Input: A = 1B = 2

 Output: 2

Note:

  1. -2147483648 <= A, B <= 2147483647

Solutions

Python3


Java

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

...