1 class Solution {
2 public:
3 int lengthOfLastWord(
const char *
s) {
4 // Start typing your C/C++ solution below
5 // DO NOT write int main() function
6 if (*s == NULL)
return 0;
7
8 int length =
0;
9 int result =
0;
10
11 while (*
s){
12
13 if (*s ==
' ') {
14 length =
0;
15 s++
;
16 }
17
18 else {
19 length++
;
20 result =
length;
21 s++
;
22 }
23 }
24
25 return result;
26 }
27 };
转载于:https://www.cnblogs.com/tanghulu321/archive/2013/05/13/3074987.html
相关资源:数据结构—成绩单生成器
转载请注明原文地址: https://win8.8miu.com/read-1553495.html