Simple c++ solution, but don't know why slow speed


  • 0
    S
    class Solution {
    public:
        int rangeBitwiseAnd(int m, int n) {
            int tester = 0x40000000;
            int result = 0;
            while(tester > 0 && (tester & m) == (tester & n))
            {
                result += (tester & m);
                tester >>= 1;
            }
            return result;
        }
    };

Log in to reply
 

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