public class Solution {
public boolean isPalindrome(int x) {
// 转换int类型为StringBuffer类型
StringBuffer sb = new StringBuffer();
sb.append(x);
String pre = null;
if (sb.length() %2 == 0) {
pre = sb.toString().substring(0, sb.length() / 2);
} else {
pre = sb.toString().substring(0, sb.length() / 2 + 1);// 前缀数
}
String suf = sb.toString().substring(sb.length() / 2, sb.length());// 后缀数
// 后缀数逆向
String target = new StringBuffer(suf).reverse().toString();
if (!pre.equals(target)) {
return false;
}
return true;
}
}