100 ms C++ solution


  • 3
    L
    class Solution {
    public:
        int rangeBitwiseAnd(int m, int n) {
            int i = n^m;
            int p = -1;
            while(i!=0){
                i>>=1;
                p<<=1;
            }
            return m&p;
        }
    };

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.