Why my answer is Time Limit Exceeded

  • 0

    When the last executed input: 2147483647, 2147483647
    It was said Time Limit Exceeded.
    But when the m==n, my solution will return m following the first 3 lines. Anyone knows why?

    public class Solution {
            public int rangeBitwiseAnd(int m, int n) {
        			   return m;
                  if(m==0)                    return 0;
        		  int a = (int) (Math.log10(m)/Math.log10(2))+1;
        		  int b = (int) (Math.log10(n)/Math.log10(2))+1;
        		  int x = m;
        		  if(a<b)       n = (int) Math.pow(2, a)-1;
        		  for(int i=m+1; i<=n; i++){
        			   x = x&i;
        			   if(i==2147483647)  break;
        		  return x;

Log in to reply

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