My solution in C (0 ms)


  • 0
    S
        int lengthOfLastWord(char* a) 
    {       
            size_t n = strlen(a);
            int count =0;int i;int flag=0;
            if(n==0) return 0;
        
        for(i=n-1;i>=0;i--)
        {
            if( (a[i]>='a'&& a[i]<='z') || (a[i]>='A' && a[i]<='Z'))
            {
                count++;
                flag=1;
            }
           else if(a[i]=' ' && flag==1)
            break;
            
        }
        
        return count;
        
        
    }

Log in to reply
 

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