注意点:小心最后有一串空格的样例
class Solution {public:int lengthOfLastWord(const char *s) {int length = 0;int i = strlen(s) - 1;while (i>=0 &&s[i] == ‘ ‘)i--;while(i>= 0&&s[i]!=‘ ‘){i--; length++;}return length;}};
原文:http://www.cnblogs.com/flyjameschen/p/12e4a03d482b6982c73a1c2b362128ee.html