`

LeetCode 9 - Palindrome Number

 
阅读更多

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

public boolean isPalindrome(int x) {
    int y = 0;
    while(x >= y) {
        y = y * 10 + x % 10;
        if(x == y || x/10 == y) {
            return true;
        }
        if(y == 0) {
            return false;
        }
        x /= 10;
    }
    return false;
}

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics