A solution without any extra space but 10 if/else and 87 lines!!!


  • 1
    W
    bool isPalindrome(int x)
    {
        if(x < 0)
            return false;
        if(x / 1000000000 == 0)
        {
            if(x / 100000000 == 0)
            {
                if(x / 10000000 == 0)
                {
                    if(x / 1000000 == 0)
                    {
                        if(x / 100000 == 0)
                        {
                            if(x / 10000 == 0)
                            {
                                if(x / 1000 == 0)
                                {
                                    if(x / 100 == 0)
                                    {
                                        if(x / 10 == 0)
                                        {
                                            return true;
                                        }
                                        else
                                        {
                                            return x / 10 % 10 == x % 10;
                                        }
                                    }
                                    else
                                    {
                                        return x / 100 % 10 == x % 10;
                                    }
    
                                }
                                else
                                {
                                    return x / 1000 % 10 == x % 10
                                            && x / 100 % 10 == x / 10 % 10;
                                }
                            }
                            else
                            {
                                return x / 10000 % 10 == x % 10
                                        && x / 1000 % 10 == x / 10 % 10;
                            }
                        }
                        else
                        {
                            return x / 100000 % 10 == x % 10
                                    && x / 10000 % 10 == x / 10 % 10
                                    && x / 1000 % 10 == x / 100 % 10;
                        }
                    }
                    else
                    {
                        return x / 1000000 % 10 == x % 10
                                && x / 100000 % 10 == x / 10 % 10
                                && x / 10000 % 10 == x / 100 % 10;
                    }
                }
                else
                {
                    return x / 10000000 % 10 == x % 10
                            && x / 1000000 % 10 == x / 10 % 10
                            && x / 100000 % 10 == x / 100 % 10
                            && x / 10000 % 10 == x / 1000 % 10;
                }
            }
            else
            {
                return x / 100000000 % 10 == x % 10
                        && x / 10000000 % 10 == x / 10 % 10
                        && x / 1000000 % 10 == x / 100 % 10
                        && x / 100000 % 10 == x / 1000 % 10;
            }
    
        }
        else
        {
            return x / 1000000000 % 10 == x % 10
                    && x / 100000000 % 10 == x / 10 % 10
                    && x / 10000000 % 10 == x / 100 % 10
                    && x / 1000000 % 10 == x / 1000 % 10
                    && x / 100000 % 10 == x / 10000 % 10;
        }
    }
    

Log in to reply
 

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