题解 | #牛牛的名字游戏#
牛牛的名字游戏
https://www.nowcoder.com/practice/92320333267c482b8de09a9b56ef6d9d
class Solution {
public:
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param s string字符串
* @return int整型
*/
int lengthOfLastWord(string s) {
// write code here
int count=0;
for(int i=s.size()-1;i>=0;i--){
if(s[i]!=' '){
count++;
}else if(i==s.size()-1||i==s.size()-2){
continue;
}else {
break;
}
}
return count;
}
};
查看17道真题和解析