9. Palindrome Number
Determine whether an integer is a palindrome. Do this without extra space.
1 class Solution { 2 public: 3 bool isPalindrome(int x) { 4 bool bRet = true; 5 int num = x; 6 int nCount = 0; 7 while(num /= 10) ++nCount; 8 while(bRet && nCount) { 9 int i1 = (x / pow(10, (double)(nCount--))); 10 int i2 = (x % 10); 11 bRet = i1 == i2 ? true : false; 12 x /= 10; 13 x -= i1 * pow(10, (double)(nCount)); 14 nCount--; 15 } 16 return bRet; 17 } 18 };

浙公网安备 33010602011771号