public boolean isPalindrome(int x) {
    int tail = x%10;
    int head = x;
    int m = 1;
    
    if(x>=0 && x<10) return true;
    if(x<0) return false;
    
    while(head>=10){
        m *= 10;
        head = x/m;
    }

    while(head == tail){
        x /= 10;
        if(x == 0) return true;
        tail = x%10;
        
        m /= 10;
        x %= m;
        m /= 10;
        if(m == 0) return true;
        head = x/m;
    }
    return false;
}