32ms c++ solution.


  • 0
    M
    class Solution {
    public:
        int rangeBitwiseAnd(int m, int n) {
            int bitmask=0xFFFFFFFF,unit=1;
            while(n-m>=unit){
                bitmask^=unit;
                if(unit<0)break;
                unit<<=1;
            }
            return m&n&bitmask;
        }
    };
    

    I can feel that c++ programs run faster these days, is that my misconception?


Log in to reply
 

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