My code:
public class Solution {
public int rangeBitwiseAnd(int m, int n) {
int i = 1;
while (m != n) {
m >>= 1;
n >>= 1;
i <<= 1;
}
return m * i;
}
}
reference:
一开始看了这个最优解
https://discuss.leetcode.com/topic/12133/bit-operation-solution-java
不明白为什么最后 m * iteration
然后看了这个:
http://www.cnblogs.com/grandyang/p/4431646.html
更加形象,就理解了。
Anyway, Good luck, Richardo! -- 10/14/2016
网友评论