面试题 05.06. 整数转换

面试题 05.06. 整数转换

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

示例1:

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

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

class Solution {
public:
    int getBits(int n){
        return __builtin_popcount(n);

    }
    int convertInteger(int A, int B) {
        return A^B;
    }
};

 

因上求缘,果上努力~~~~ 作者:每天卷学习,转载请注明原文链接:https://www.cnblogs.com/BlairGrowing/p/13553161.html

原文地址:https://www.cnblogs.com/BlairGrowing/p/13553161.html