My C++ solution. And what's the meaning of generic?


  • -1
    B
    class Solution {
    public:
        bool isPalindrome(int x) {
            if (x < 0) return false;
            if (x / 10 == 0) return true;
            
            unsigned char r[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
            int len = 0;
            do {
                r[len++] = x % 10;
            } while (x /= 10);
    
            for (int i = 0; i < (len >> 1); ++i) {
                if (r[i] != r[len - 1 - i]) return false;
            }
            return true;
        }
    };
    

    I have no idea whether my solution is a generic one or not.


Log in to reply
 

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