[Leetcode] Palindrome Number (no extra space is used)
It is easy to judge the return string. You only need to reverse the string and compare it with the original string. This question clearly indicates that no extra space is available, so it is not feasible to break it into strings. We had to use the mathematical method: each time we take the highest bit and the second bit, we can use a while to process the total number of digits first, until the remainder and the divisor are equal.
For details, see the code:
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 ;}};