Palindrome Number

Palindrome Number

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

 

public class Solution {
    public boolean isPalindrome(int x) {
    // http://blog.csdn.net/linhuanmars/article/details/21145231
        if(x<0) return false;
        int div = 1;
        while(x/div>=10){
            div *=10;
        }
        while(x>0){
            if(x/div!=x%10)
                return false;
            x = (x%div)/10;
            div/=100;
        }
        return true;
    }
}

 

posted @ 2015-05-29 05:57  世界到处都是小星星  阅读(100)  评论(0编辑  收藏  举报