[leetcode] Palindrome Number

题目:

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

解题思路:

循环取得首位和末尾,然后比较。

解题心得:

关于整数的处理有几个 运算需要熟记:

一个整数:

 %10 得个位 , %100 的后两位 就是个位和十位 %1000...依次类推

 /10 去个位 得从十位开始的数 , /100 去十位 个位, 得从百位开始的数... 依次类推;

public class Solution {
    public boolean isPalindrome(int x) {
        if(x<0) 
           return false;
        
        int div=1;
        while(x/div>=10)
            div*=10;
        
        while(x!=0)
        {
            int last =x%10 ;
            int first = x/div;
            if(first!=last) return false;
            
            x =(x%div)/10;
            div/=100;
        }
        
        return true;
    }
}
原文地址:https://www.cnblogs.com/fengmangZoo/p/4741346.html