首页 > 其他 > 详细

LintCode: Flip Bits

时间:2015-11-30 11:31:18      阅读:269      评论:0      收藏:0      [点我收藏+]

C++

 1 class Solution {
 2 public:
 3     /**
 4      *@param a, b: Two integer
 5      *return: An integer
 6      */
 7     int bitSwapRequired(int a, int b) {
 8         // write your code here
 9         unsigned int tmpA = a;
10         unsigned int tmpB = b;
11         int steps = 0;
12         while (tmpA || tmpB) {
13             steps += (tmpA&0x1)^(tmpB&0x1);
14             tmpA >>= 1;
15             tmpB >>= 1;
16         }
17         return steps;
18     }
19 };

 

LintCode: Flip Bits

原文:http://www.cnblogs.com/CheeseZH/p/5006644.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!