My 47ms simple C code


  • 0
    A
    bool isPalindrome(int x) {
        int temp = x;
        
        long long reverse = 0;
        
        while (temp > 0){
            reverse = reverse*10 + temp%10;
            temp /= 10;
        }
        
        return (reverse == (long long)x) ? true : false;
    }

  • 1
    S

    I think the last line

    return (reverse == (long long)x) ? true : false;
    

    can be writen as

    return  reverse == (long long)x;
    

    for short.


  • 0
    A

    hmm, correct. I should've realized that :) Thanks for pointing it out.


Log in to reply
 

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