No reverse solution


  • 0
    E
    bool isPalindrome(int x) {
        if(x < 0) return false;
        
        int a = 1;
        int len = 1;
        int temp = x/10;
        while(temp != 0) {
            a *= 10;
            temp /= 10;
            ++len;
        }
        
        len /= 2;
        int x1 = x;
        while(len > 0) {
            if(x1/a != x%10) return false;
            x1 %= a;
            a /= 10;
            x /= 10;
            --len;
        }
        
        return true;
    }
    

    Basically get the length of the number, and largest tens.


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.