您的位置:首页 > 其它

Length of last word

2013-05-13 03:52 162 查看
class Solution {
public:
int lengthOfLastWord(const char *s) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
if (*s == NULL) return 0;

int length = 0;
int result = 0;

while (*s){

if (*s == ' ') {
length = 0;
s++;
}

else {
length++;
result = length;
s++;
}
}

return result;
}
};
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: