Simple C++ Solution Counting Different Lower Bits


  • 0
    M
    class Solution {
    public:
        int rangeBitwiseAnd(int m, int n) {
            int len = 0;
            while (m != n) { m >>= 1; n >>= 1; ++len; }
            return m << len;
        }
    };
    

Log in to reply
 

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