Just picture the shifting process in your mind..
class Solution { public: int rangeBitwiseAnd(int m, int n) { if (m == n) return m; int r = 0; int cnt = 0; while (m && m < n) { cnt++; m >>= 1; n >>= 1; } if (m == n && m > 0) r = m << cnt; return r; } };