Why is this code got TLE?


  • 2
    G
    public int rangeBitwiseAnd(int m, int n) {
        if (m == n) {
        	return m;
        }    
        if (m - n == 1) {
            return m & n;
        }
        //else m == n
    	return rangeBitwiseAnd(m >> 1, n >> 1) << 1;  //忘了m-n == 1!!!
        }
    

    I got TLE on this case: 2147483647 2147483647. Isn't it just return 2147483647?


  • 0
    D

    I have the same question.


  • 0
    D

    my code that used to pass got TLE as well...


  • 0
    L

    That is the reason of new testing case, you just put "if(m==Integer.MAX_VALUE&&m==n) return n;" in your code, then your answer will be accepted.


  • 0
    D

    I got the same problem. And the answer below could not work.


  • 0

    I have just fixed this issue. Your code should get AC now.


Log in to reply
 

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