C 32ms solution using mask

  • 0
    int rangeBitwiseAnd(int m, int n) 
        int msb=0;
        int t = m ^ n;
        while (t >>= 1)
        unsigned int mask = ~((1 << msb) -1);
        return m & mask;

  • 0

    the code I wrote here is not correct, so I removed it in case someone might be misled...

Log in to reply

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