Using log2 in c++ 114ms


  • 0
    Y
    class Solution {
    public:
        int rangeBitwiseAnd(int m, int n) {
            if(m==n) return m;
            int k = floor(log2(n-m))+1;
            int result = m&(n-n%(int(pow(2,k))));
            return result;
        }
    };

Log in to reply
 

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