LeetCode 009 Palindrome Number

来源:互联网 发布:java jdbc 连接 编辑:程序博客网 时间:2024/06/06 21:43

题目描述

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

代码

    public static boolean isPalindrome(int x) {        if (x < 0) {            return false;        }        if (x >= 0 && x < 10) {            return true;        }        int d = 1;        while (x / d >= 10) {            d *= 10;        }        while (x != 0) {            // 若首尾不相等,返回false            if (x % 10 != x / d) {                return false;            }            x = x % d / 10;            d /= 100;        }        return true;    }
1 0
原创粉丝点击