面试题 05.06. 整数转换

题目:

 

 

解答:

 

 

class Solution {
public:
    int convertInteger(int A, int B) 
    {
        int res = 0;
        int temp = A ^ B;
        while (temp!=0)
        {
            int lowbit = temp & (-temp);
            res++;
            temp-=lowbit;
        }
        return res;
    }
};

 

posted @ 2020-05-09 23:28  梦醒潇湘  阅读(121)  评论(0)    收藏  举报