首页 > 其他 > 详细

LeetCode Length of Last Word

时间:2014-06-29 13:47:30      阅读:348      评论:0      收藏:0      [点我收藏+]
bubuko.com,布布扣
class Solution {
public:
    int lengthOfLastWord(const char *s) {
        if (s == NULL) return 0;
        int mlen = 0, len = 0;
        bool inword = false;
        int pos = 0;
        char ch = 0;
        while ((ch = s[pos]) != \0) {
            if (ch !=  ) {
                if (!inword) inword = true;
                len++;
            } else if (inword) {
                if (len > 0) mlen = len;
                len = 0;
                inword = false;
            }
                pos++;
        }
        if (len > 0) mlen = len;
        return mlen;
    }   
};
bubuko.com,布布扣

水一发

LeetCode Length of Last Word,布布扣,bubuko.com

LeetCode Length of Last Word

原文:http://www.cnblogs.com/lailailai/p/3755799.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!