判斷一個整數是否是回文數。回文數是指正序(從左向右)和倒序(從右向左)讀都是一樣的整數。
class Solution {
public:
bool isPalindrome(int x) {
if (x < 0)
return false;
int temp = x;
int res = 0;
while (x)
{
res = res * 10 + x % 10;
x /= 10;
}
return temp == res;
}
};