标签:
1 class Solution { 2 public: 3 bool isPalindrome(int x) { 4 int left = 1; 5 int right = 10; 6 int temp = x; 7 while (temp >= 10) { 8 left *= 10; 9 temp /= 10; 10 } 11 if (x < 0) return false; 12 if (left == 1) return true; 13 else { 14 if (left == 10) return x / 10 == x % 10; 15 while (left >= right) { 16 int a = x / left % 10; 17 int b = x % right / (right / 10); 18 if (a != b) return false; 19 left /= 10; 20 right *= 10; 21 } 22 return true; 23 } 24 } 25 };
标签:
原文地址:http://www.cnblogs.com/shadowwalker9/p/5752789.html