class Solution {
public:
    int lengthOfLastWord(string s) {
        if(s.size() == 0) {
            return 0;
        }
        reverse(s.begin(), s.end());
        int L = 0;
        while(L < s.size() && s[L] == ' ') {
            ++L;
        }
        int R = L;
        while(R < s.size() && s[R] ! =' ') {
            ++R;
        }
        returnR - L; }};Copy the code