解題思路:
(1)首先將整形數轉爲字符串,然後判斷首尾字符是否相等,依次比較
class Solution {
public:
bool isPalindrome(int num) {
string str = to_string(num);
int i=0,j=str.length()-1;
while(i<=j) {
if(str[i]!=str[j]) return false;
else i++,j--;
}
return true;
}
};