您的位置:首页 > 其它

[LintCode] 最后一个单词的长度

2015-06-28 15:57 225 查看
class Solution {
public:
/**
* @param s A string
* @return the length of last word
*/
int lengthOfLastWord(string s) {
int len = 0, tail = s.length() - 1;
while (tail >= 0 && s[tail] == ' ') tail--;
while (tail >= 0 && s[tail] != ' ') {
len++;
tail--;
}
return len;
}
};
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: