int lengthOfLastWord(char * s){
    if(strlen(s) == 0)
    return 0;
int x =strlen(s)-1;
while(s[x]==' '){
    x-=1;
    if(x<0)
    return 0;
}
int j = 0;
while(s[x]!= ' '){
    x-=1;
    j+=1;
    if(x<0)
    return j;
}
return j;
}

回头学下KMP

此文章已被阅读次数:正在加载...更新于