首页 > 代码库 > leetcode 9.Palindrime Number

leetcode 9.Palindrime Number

技术分享

public class Solution {
    public boolean isPalindrome(int x) {
        
        if(x < 0)
        return false;
        
        if(x < 10)
        return true;
        
        int i = 1;
        int tmpx = x;
        while(tmpx/10 != 0)
        {
            i *= 10;
            tmpx /= 10;
        }
        
        while(x != 0)
        {
            int left = x % 10;
            int right = x / i;
            
            if(left != right)
            return false;
            else
            {
                x = (x%i)/10;//x%i 去头 (x%i)/10去尾
                i /= 100;//少了两个数字,位数少2
            }
        }
        
        return true;
    }
}

 

leetcode 9.Palindrime Number