leetcode上碰到的一个题,得到结果很简单,但是花的时间有点长,求高效解法 Given a range [m, n] where 0 <= m <= n <= 2147483647, return the bitwise AND of all numbers in this range, inclusive. For example, given the range [5, 7], you should return 4. 下面这样的算法,效率是不行的 public int rangeBitwiseAnd(int m, int n) { int result = n; for(int i = m; i < n; i++) { result = result & i; } return result; } }
|