class Solution { public: bool isPalindrome(int x) { if(x < 0) return false; if(x < 10) return true; int temp1; int temp2; int dx = 0; int t = x; while(t != 0) { t = t/10; ++dx; } t = x; int left = pow(10, dx - 1); while(t != 0) { temp1 = t % 10; t = t /10; temp2 = x / left % 10; if(temp1 == temp2) { left = left/10; } else return false; } return true; } };
Palindrome Number
不能开辟新的内存,因此只能通过取模等运算。还算简单。