9. Palindrome Number

  • first attempt
class Solution {
public:
    bool isPalindrome(int x) {
        //reverse number is the same
        if(x<0)
            return false;
        if(x == 0)
            return true;
        int same = x;
        int result = 0 ;
        int bit;
        while(same!=0)
        {
            bit = same%10;
            result = result*10+bit;
            same/=10;
        }
        return (result==x);
    }
};

你可能感兴趣的:(9. Palindrome Number)