Palindrome Number

来源:互联网 发布:windows 10 redstone 编辑:程序博客网 时间:2024/05/19 23:54

题目描述:

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

不适用额外的空间,就是不能使用数组,也不能使用字符串了。

负数不是回文数,最小的回文数是0.

pow函数参数和返回值都是double精度。

代码如下:

public class Solution {    public boolean isPalindrome(int x) {        int n=0;        if(x<0)            return false;        int y=x;        while(y!=0){            y/=10;            n++;        }        while(n>1){            if(x%10!=x/(int)Math.pow(10, n-1))                return false;            x=(int)(x%(int)Math.pow(10, n-1)/10);            n-=2;        }        return true;    }}


0 0