标签:style blog http java color os
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; } };
水一发
LeetCode Length of Last Word,布布扣,bubuko.com
标签:style blog http java color os
原文地址:http://www.cnblogs.com/lailailai/p/3755799.html