C 0ms


  • 0
    D
    int lengthOfLastWord(char* s)
    {
        int i=0,nc=0,j=0;
    
        for(;s[i]!='\0';i++)
        {
            if(isalpha(s[i]))
            {   ++nc;
                continue;
            }
    
        if(isspace(s[i]))
        {
            for(j=i;s[j]!='\0';j++)    //find trailing white space
                {   
                    if(isspace(s[j]))
                        continue;
                    else
                        break;
                }
                    if(s[j]!='\0')
                        nc=0;
               }        
       }
    
        return nc;
    }

Log in to reply
 

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