Your browser does not seem to support JavaScript. As a result, your viewing experience will be diminished, and you have been placed in read-only mode.

Please download a browser that supports JavaScript, or enable it if it's disabled (i.e. NoScript).

public int rangeBitwiseAnd(int m, int n) { int shiftCount = 0; while(m != n) { n = n >> 1; m = m >> 1; shiftCount++; } return n << shiftCount; }

If m != n, then there are zero or more numbers in between them. And every consecutive number differs by the rightmost bit. The right-most zero will turn that bit into zero in the final result, hence we can shfit through that bit till m == n.

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