9. Palindrome Number

class Solution {
public:
    bool isPalindrome(int x) {
        if (x < 0 || (x != 0 && x % 10 == 0)) return false;
                    //x != 0 !!!!!!!!!!!!
        int r = 0;
        while (x > r) {
            r = r * 10 + (x % 10);
            x /= 10;
        }
        return (x == r) || (x == r / 10);
    }
};

results matching ""

    No results matching ""