首页 > 其他 > 详细

LeetCode "Bitwise AND of Numbers Range"

时间:2015-04-16 14:07:06      阅读:602      评论:0      收藏:0      [点我收藏+]

Just picture the shifting process in your mind..

class Solution {
public:
    int rangeBitwiseAnd(int m, int n) {
        if (m == n) return m;
        int r = 0;
        int cnt = 0;
        while (m && m < n)
        {    
            cnt++;
            m >>= 1;
            n >>= 1;
        }
        if (m == n && m > 0)
            r = m << cnt;
        return r;
    }
};

LeetCode "Bitwise AND of Numbers Range"

原文:http://www.cnblogs.com/tonix/p/4431765.html

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