It is easy to judge a palindrome string, just reverse the string and compare it to the original string. This topic clearly indicates that additional space cannot be used, so it is not feasible to use the method of splitting it into strings. Had to adopt the mathematical way: each time to take the highest and lowest phase comparison, the total number of bits can be processed out with a while, loop until the remainder and the divisor equal.
See the code for details:
Class Solution {public: bool Ispalindrome (int x) { if (x<0) //special due return false; if (x<10) return true; int curmod=0; int test=x; while (test) { curmod++; test/=10; } curmod--;//bit num int left=pow (10,curmod*1.0), right=10; while (Right<=left) { if (X%right!=x/left) return false; x=x%left,x/=10; left/=100; } return true; }};
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
[Leetcode] Palindrome number (no extra space is used)