leetcode 201.Bitwise AND of Numbers Range

Posted newnoobbird

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了leetcode 201.Bitwise AND of Numbers Range相关的知识,希望对你有一定的参考价值。

要求求出在一个序列中的所有数字的二进制的和,那么会发现左边相与相等即可的,则可以利用最大值的不断右移来实现的。

class Solution {
public:
    int rangeBitwiseAnd(int m, int n) {
        int t=INT_MAX;
        while((m&t)!=(n&t)){
            t<<=1;
        }
        return m&t;
    }
};

 

以上是关于leetcode 201.Bitwise AND of Numbers Range的主要内容,如果未能解决你的问题,请参考以下文章