LeetCode 201

题目描述:

知识点:位运算

低位混乱,& 出来的结果不会一致,所以只需要看最小数和最大数对应的高位情况。

public static int rangeBitwiseAnd3(int m, int n) {
        if(m == 0){
            return 0;
        }
        int temp = 1;
        while(m != n){
            m >>= 1;
            n >>= 1;
            temp <<= 1;
        }
        return m * temp;

    }

 

posted @ 2020-08-24 18:34  君莫笑我十年游  阅读(97)  评论(0编辑  收藏  举报