C 4ms Solution


  • 1
    D

    bool isPalindrome(char* s)
    {
    int i,j;

     i=0;
     j=strlen(s)-1;
    
     if(strcmp(s,"")==0)
         return true;
    
    
     for(;i!=j && i<j;)
        {
            if(isspace(s[i]))
                i++;
            else if(ispunct(s[i]))
                i++;
            else if(isspace(s[j]))
                j--;
            else if(ispunct(s[j]))
                j--;
            else if(tolower(s[i]) ==tolower(s[j]))
                  {   i++; j--; }
            else
                return false;
        }
    
        return true;
    

    }


  • 0
    S
    class Solution {
    public:
        bool isPalindrome(string s) {
            int i,j;
    
     i=0;
     j=s.length()-1;
    
     if(s.compare("")==0)
         return true;
    
    
     for(;i!=j && i<j;)
        {
            if(isspace(s[i]))
                i++;
            else if(ispunct(s[i]))
                i++;
            else if(isspace(s[j]))
                j--;
            else if(ispunct(s[j]))
                j--;
            else if(tolower(s[i]) ==tolower(s[j]))
                  {   i++; j--; }
            else
                return false;
        }
    
        return true;
        }
    };
    

  • 0
    D
    How many milliseconds?

Log in to reply
 

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