Problem:
Determine whether an integer is a palindrome. Do the 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.
Thinking:
(1) Before the reverse reversal of int type, here to check whether a number is a palindrome number, you can get a little inspiration.
(2) Reverse reversal mainly involves the processing of overflow problem, and the spatial complexity of inversion can be neglected and meet the requirement of the topic.
Code
Class Solution {public: bool Ispalindrome (int x) { int b=0; int a=x; BOOL Flag=true; if (a<0) { bool flag=false; a=-x; } while (a) { b*=10; b+=a%10; A=A/10; } if (b>2147483647) return false; if (!flag) b=-b; return (b==x);} ;
Leetcode | | Palindrome number question