palindrome-number

题目链接

思路

首先将intege整数进行反转 ,可以参考reverse-integer那道题
然后比较翻转后的数和现在的数时候相同

需要考虑的情况

正负数 溢出

public class Solution {
    public boolean isPalindrome(int x) {
        int buf = x;
        int flag = 1;
        if(x<0) flag = -1;
        long result = 0;
        while(x>0){
            result = result *10 +x%10;
            x = x/10;
        }

        if(flag*result == buf){
            return true;
        }
        return false;  
    }
}

你可能感兴趣的:(leedcode)