C 0ms


  • 1
    T
    int lengthOfLastWord(char* s) {
        int len = strlen(s), wordLen = 0;
        while (len--) {
            if (s[len] == ' ' && wordLen) {
                break;
            } else if (s[len] != ' ') {
                wordLen++;
            }
        }
        return wordLen;
    }
    

  • 0
    G

    I like how you use wordLen to check whether we're to / past the last word, very clever


Log in to reply
 

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