LeetCode Palindrome Number

来源:互联网 发布:开淘宝店铺方便自己吗 编辑:程序博客网 时间:2024/06/14 02:05

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

/** * 判断整数是否为回文, * 负数不是,10整数倍不是.0~9是. * Created by ustc-lezg on 16/4/6. */public class Solution {    public boolean isPalindrome(int x) {        if (x < 0) {            return false;        }        if (x < 10) {            return true;        }        if (x % 10 == 0) {            return false;        }        int y = 0;        while (x > y) {            y = y * 10 + x % 10;            x /= 10;        }        if (y > x) {//x为奇数,y > x            y /= 10;        }        return x == y ? true : false;    }}
0 0