BiruLyu
6/21/2017 - 6:58 AM

9. Palindrome Number(half).java

class Solution(object):
    def isPalindrome(self, x):
        """
        :type x: int
        :rtype: bool
        """
        
        if x < 0 or (x != 0 and x % 10 == 0 ):# negative integer can not be a palindrome number 
            return False;                     # if an integer ends with 0, it can not be a palindrome number
        
        y = 0;
        while(x > y):
            y = y * 10 + x % 10;
            x = x / 10;
        
        return x == y or x == y / 10; # store a Reverse Integer of half of x 
        
        
public class Solution {
    public boolean isPalindrome(int x) {
        int num = x;
        int y = 0;
        while (num > 0) {
            y = y * 10 + num % 10;
            num /= 10;
        }
        return x == y;
    }
}
public boolean isPalindrome(int x) {
    if (x<0 || (x!=0 && x%10==0)) return false;
    int rev = 0;
    while (x>rev){
    	rev = rev*10 + x%10;
    	x = x/10;
    }
    return (x==rev || x==rev/10);
}