Why it is always Memory Limit Exceeded in the last testcase


  • 4
    N

    My code

    bool isPalindrome(int x){
    	if(x < 0) return false;
    	if(x < 10) return true;
    	int len = 1, num = x;
    	while(num / 10){
    		len ++;
    		num /= 10;
    	}
    	int first = pow(10, len - 1), last = 1;
    	for(int i = 0; i < len / 2; i ++){
    		if(x / first % 10 != x / last % 10) return false;
    		first /= 10;
    		last *= 10; 
    	}
    	return true;
    }
    

    If "without extra space" is the meaning of O(1), I think my code is corrent. But the submission result is Memory Limit Exceeded in the last testcase.

    In fact, I have try to submit a code from the top solution, but it is also Memory Limit Exceeded.


  • 0
    A

    I am also getting the same thing


  • 0
    L

    I'm struggling with the same problem..

    bool isPalindrome(int x) {
    
      if (x< 0) return false;
      if (x<10) return true;
      if (x%10 == 0) return false;
    
      int high= 1e9;
      while (high > x) high = high/10;
    
      int low= 1;
      
      while (high>=low){
        if ((int(x/high)%10) != (int(x/low)%10))
          return false;
        high/=10;
        low*=10;
      }
    
      return true;
    }
    

  • 0
    N

    @agarwal.shubham7599
    Hmmm...I still have no idea to solve this problem...Though I have solved several problems on leetcode which prohibits to use extra space.


  • 0
    N

    @lhufnagel
    In fact,I have no idea why the error would happen.So I give up and if your code is accepted, plz tell me how to deal with it. orz


  • 0

    This was just fixed, sorry about that.


Log in to reply
 

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