C, One line, 6mS


  • 0
    M

    Well, as you can see, the recursive function exploits the ternary operator.

    bool isRPalindrome(char *s1, char *s2)
    {
        return  (s1 >= s2) ? true : (toLower(*s1) == toLower(*s2)) ? 
                isRPalindrome(++s1, --s2) : (!isAlphaNum(*s1)) ? 
                isRPalindrome(++s1, s2): (!isAlphaNum(*s2)) ? 
                isRPalindrome(s1, --s2): false;
    }
    bool isPalindrome(char* s)
    {
        int len = strlen(s);
        return isRPalindrome(s, s + len - 1);
    }
    

Log in to reply
 

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