您的位置:首页 > 其它

Length of Last Word

2013-07-24 18:54 176 查看
class Solution {
public:
int lengthOfLastWord(const char *s) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
int len=strlen(s),p=len-1,cnt=0;
while(p>=0&&s[p]==' '){
--p;
}
while(p>=0&&s[p]!=' '){
--p;
++cnt;
}
return cnt;
}
};
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: