My C 0ms solution


  • 1
    C
    int lengthOfLastWord(char* s) {
        int len = strlen(s);
        int lenlast = 0; /*the length of last word in the string*/
        if (len == 0) return 0;
        while (s[len - 1] == ' ') 
            len --;
        for ( --len; len >= 0 && s[len] != ' ' ; len--) 
            lenlast++;
        return lenlast;
    }

Log in to reply
 

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