My c++ solution. around 110ms


  • 3
    J

    class Solution {
    public:
    bool isPalindrome(int x) {
    if(x<0)
    return false;
    if( x < 10)
    return true;
    int target = 0;
    int orgin = x;
    while(orgin != 0){
    target = target * 10 + orgin % 10;
    orgin /= 10;
    }
    return target == x;
    }
    };

    negative number is not palindrome. Reverse the given number and compare.


  • 0
    K

    Thanks,The Solution is quite perfect!!!


  • 0
    A

    What's about overflow? target can be too big.


  • 0
    A

    This answer is quite clear!


Log in to reply
 

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