Palindrome number
Determine whether an integer is a palindrome. Do this without extra space.
Click to show spoilers.
Some hints:
Could negative integers be palindromes? (ie,-1)
If you is thinking of converting the integer to string, note the restriction of using extra space.
You could also try reversing an integer. However, if you had solved the problem "Reverse integer", you know that the reversed integer might overflow. How do would handle such case?
There is a more generic the solving this problem.
raise int to long long int first, because the inverse of int may be more than Int_max.
Then we can find out the inverse number y of x and judge whether the two are equal.
classSolution { Public: BOOLIspalindrome (intx) {if(X <0) return false; Else returnHelper (x); } BOOLHelper (Long Long intX//incase of overflow { Long Long intt =x; Long Long inty =0; while(t) {y= y*Ten+ t%Ten; T/=Ten; } return(Y = =x); }};
"Leetcode" palindrome number