leetcode58 C++ 4ms 最后一个单词的长度

class Solution {
public:
    int lengthOfLastWord(string s) {
        auto p = (int)(s.size()-1);
        string res;
        while(p>=0 && s[p] == ' '){
            p--;
        }
        while(p>=0 && s[p]!=' '){
            res.push_back(s[p]);
            p--;
        }
        reverse(res.begin(), res.end());
        return res.size();
    }
};
原文地址:https://www.cnblogs.com/theodoric008/p/9376675.html