LeetCode9. 回文数isPalindrome(Math)

1、题目描述

2、代码详解

public class IsPalindrome_9 {
    public static void main(String[] args){
        int x =1221;
        System.out.println(isPalindrome(x));
    }
    public static boolean isPalindrome(int x){
        // 末尾为 0 就可以直接返回 false ,例如 90
        if(x < 0 || (x % 10 == 0 && x != 0)) return false;
        int revertedNumber = 0;
        while(x > revertedNumber){
            revertedNumber = revertedNumber*10 + x%10;
            x /= 10;
        }
        return x == revertedNumber || x == revertedNumber /10;

    }
}

https://www.cxyxiaowu.com/6847.html

发布了184 篇原创文章 · 获赞 225 · 访问量 5万+

猜你喜欢

转载自blog.csdn.net/IOT_victor/article/details/105188745