Leetcode 9 Palindrome Integer
题目大意
判断一个int(32 bit)是否是回文数。
解题思路
同Leetcode 7,注意负数不是回文数。
class Solution {
public:
bool isPalindrome(int x) {
if (x < 0) return false;
long long n = 0;
int tmp = x;
while (tmp != 0) {
n = n * 10 + tmp % 10;
tmp = tmp / 10;
}
if (n == (long long)x) {
return true;
}
else
return false;
}
};