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
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