题解 | #牛牛的名字游戏#
牛牛的名字游戏
https://www.nowcoder.com/practice/92320333267c482b8de09a9b56ef6d9d
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param s string字符串
* @return int整型
*/
#include<stdlib.h>
#include<stdio.h>
int lengthOfLastWord(char* s ) {
// write code here
int len=strlen(s);
int i;
int j;
for(i=len-1;s[i];i--)
{
if(' '==s[i])
{
len--;
}
else
{
break;
}
}
for(j=len-1;s[j];j--)
{
if(' '==s[j])
{
break;
}
}
if(1==len)
{
return len-j-2;
}
else {
return len-j-1;
}
}
SHEIN希音公司福利 258人发布
