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         const char *p,*q;
 7         p=s;
 8         q=p+strlen(p)-1;
 9         
10         while(p<q)
11         {
12             if(*q==' ')
13                 q--;
14             else
15                 break;
16         }
17 
18         int i=0;
19         while(*q!=' '&&p<=q)
20         {
21             q--;
22             i++;
23         }
24         return i;
25     }
26 };

 

posted on 2013-04-30 22:45  宇睿  阅读(144)  评论(0编辑  收藏  举报