# Why it is always Memory Limit Exceeded in the last testcase

• 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.

• I am also getting the same thing

• 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;
}
``````

• @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.

• @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

• This was just fixed, sorry about that.

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