Leetcode#58 Length of Last Word

原题地址

简单模拟题

代码:

 1 int lengthOfLastWord(const char *s) {
 2         char prev = ' ';
 3         int length = 0;
 4         
 5         while (*s) {
 6             if (*s != ' ') {
 7                 if (prev == ' ')
 8                     length = 1;
 9                 else
10                     length++;
11             }
12             prev = *s;
13             s++;
14         }
15         
16         return length;
17 }
原文地址:https://www.cnblogs.com/boring09/p/4266819.html