标签:
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; } };
LeetCode "Bitwise AND of Numbers Range"
标签:
原文地址:http://www.cnblogs.com/tonix/p/4431765.html