标签:style blog color ar sp div on log bs
Determine whether an integer is a palindrome. Do this without extra space.
Notes:
1) Negative number is not palindrome.
2) Compare from head to tail, consinder numbers like 10021.
1 bool isPalindrome(int x) 2 { 3 int base = 1; 4 5 if (x < 0) 6 return false; 7 8 while (x / base >= 10) 9 base *= 10; 10 11 while (x > 0) 12 { 13 if ((x / base) != (x % 10)) 14 return false; 15 x = (x % base) / 10; 16 base /= 100; 17 } 18 19 return true; 20 }
标签:style blog color ar sp div on log bs
原文地址:http://www.cnblogs.com/ym65536/p/4083552.html