原题地址

 

简单模拟题

 

代码:

 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 }

 

相关文章:

  • 2022-01-28
  • 2021-07-04
  • 2021-05-24
  • 2021-08-20
  • 2021-09-11
猜你喜欢
  • 2021-08-21
  • 2021-08-15
  • 2021-10-30
  • 2021-12-24
  • 2021-05-17
  • 2022-01-14
  • 2022-02-08
相关资源
相似解决方案