# JAVA solution according to the hint...

• ``````public boolean isPalindrome(int x) {
int i=1;
if(x<0) return false;
while(i<=x/10)
{
i*=10;
}
for(int j=1;j<i;j*=10,i/=10)
{
int dh=(x/i)%10;
int dl=(x/j)%10;
if(dh!=dl) return false;
}
return true;
}``````

• int i
int dl
int dh

these are not extra space????

• Yes, they are extra space. Do you seek the solution with space complexity O(0)? I think it could be a great solution if it really existed.

• I didn't mean that. If the palindrome number is very long, the INT or even LONG LONG type cannot store it. Then, you must use a string or other structure to store the number. In this case, the space complexity will be O(length(n)).

The point is if you can flip the half of the linked list, then not matter how long the list is we still can use the same constant space to solve it.

Furthermore, the fact that the number given by the problem is stored in a list actually implicit that the length may be too long to store in a INT or whatever variable.

• Sorry, I thought this is another problem.

• ..So, yeah..it's ok. XD

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