首页 > 代码库 > 9. Palindrome Number

9. Palindrome Number

Determine whether an integer is a palindrome. Do this without extra space.

Solution1:

思路:按题目的意思就是负数不能是palindrome。用reverse integer函数判断即可。

public class Solution {    public boolean isPalindrome(int x) {        if(x<0)        {            return false;        }        if(x==reverse(x))        {            return true;        }        return false;            }    public int reverse(int x) {    int sign=(x>=0)?1:-1;    x=Math.abs(x);    int res=0;    while(x>0)    {                if(res>Integer.MAX_VALUE/10)        {            return 0;        }        res=res*10+x%10;        x/=10;    }    return res*sign;    }}

 

9. Palindrome Number