0 ms straightforward C code


  • 0
    T

    int lengthOfLastWord(char* s) {
    int length = 0;
    int last = 0;

    while(*s!=NULL) {
        if (*s==' ' && *(s-1)!=' ') {
    
            last = length;
            length = 0;
        } 
        else if(*s!=' ') {
            length++;
        }
        s++;
    }
    
    return (*(s-1)==' ')? last : length;
    

    }


Log in to reply
 

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