C solution with few code.


  • 0
    H
    int lengthOfLastWord(char* s) {
        int i=strlen(s)-1, count=0;
        while(i>=0)
        {
            if(s[i]==' ') 
            {
                i--;
                continue;
            }
            count++;
            i--;
            if(s[i]==' ') break;
        }
        return count;
    }

Log in to reply
 

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