c++ 25ms


  • 0
    X
    class Solution {
    public:
        int rangeBitwiseAnd(int m, int n) {
            int result = 0;
            for(int i = 0; i < 32; i++){
                int currDigit = 1 << i;
                if(n-m < currDigit && m & currDigit && n & currDigit){
                    result += currDigit;
                }
            }
            return result;
        }
    };
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.