9. Palindrome Number

来源:互联网 发布:淘宝网男士运动套装 编辑:程序博客网 时间:2024/06/01 23:49

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


public class Solution {    public boolean isPalindrome(int x) {        if(x < 0){            return false;        }                int divide = 1;        while(x/divide >= 10){            divide *= 10;        }                while(x != 0){            int left = x / divide;            int right = x % 10;                        if(left != right){                return false;            }                        x = (x % divide) / 10; //掐头去尾            divide /= 100;        }                return true;    }}



原创粉丝点击