Skip to content

Latest commit

 

History

History
17 lines (17 loc) · 414 Bytes

58.md

File metadata and controls

17 lines (17 loc) · 414 Bytes

#58. Length of Last Word 题目链接

int lengthOfLastWord(char* s) {
    int length = 0;
    int i;
    for(i=0; s[i]!='\0'; i++)
    {
        if(s[i]!=' ')
            length ++;
        // 判断是否为最后一个字符,如果不是,length置为0
        else if(s[i+1]!=' '&&s[i+1]!='\0')
            length = 0;
    }
    return length;
}