- 转成string,用回文串的思路去做。
class Solution {
public:
/**
*
* @param x int整型
* @return bool布尔型
*/
bool isPalindrome(int x) {
// write code here
if (!x) return true;
string x_s = to_string(x);
for(int i = 0; i< x_s.size()/2;i++){
if(x_s[i] != x_s[x_s.size()-i-1]){
return false;
}
}
return true;
}
};
京公网安备 11010502036488号