题目:
给你一个整数 x ,如果 x 是一个回文整数,返回 true ;否则,返回 false 。
回文数是指正序(从左向右)和倒序(从右向左)读都是一样的整数。
例如,121 是回文,而 123 不是。
思路1:转字符串
python
class Solution(object):
def isPalindrome(self, x):
"""
:type x: int
:rtype: bool
"""
return str(x) == str(x)[::-1]
java
public class solution9 {
public static void main(String[] args) { //主方法
int x = 1234321;
solution9 sol = new solution9();
System.out.println(sol.isPalindrome(x));//调用方法
}
public boolean isPalindrome(int x) {
if(x < 0){
return false;
}
String strx = "" + x;
String newStr = new StringBuilder(""+x).reverse().toString();