您的位置:首页 > 其它

字符串 Length of Last Word

2015-04-09 21:03 190 查看
思想:

只有字母、空格、'\0'三种类型的字符。

class Solution {
public:
    int lengthOfLastWord(const char *s) {
        if(s == NULL) return 0;
        int length = 0;
        while(*s) {
            if(*s++!=' ') {
                length++;
            }else if(*s && *s!=' ') {
                length = 0;
            }
        }
        return length;
    }
};
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: