Share 2 Short Java Solutions


  • 0
    M

    Solution 1

        public int rangeBitwiseAnd(int m, int n) {
            int mask = ~0;
            while ((mask & m) != (mask & n)) mask <<= 1;
            return mask & m;
        }
    

    Solution 2

        public int rangeBitwiseAnd(int m, int n) {
            while (n > m) n &= n - 1;
    		return m & n;
        }
    

Log in to reply
 

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