【LeetCode刷题】--9.回文数

9.回文数

【LeetCode刷题】--9.回文数_第1张图片

class Solution {
    public boolean isPalindrome(int x) {
        if(x < 0){
            return false;
        }
        int tmp = x, sum = 0;
        boolean flag = false;
        while(x != 0){
            sum = sum * 10 + x % 10;
            x /= 10;
        }
        if(sum == tmp){
            flag = true;
        }
        return flag;
    }
}

你可能感兴趣的:(LeetCode,leetcode,算法)