class Solution {

public:

int lengthOfLastWord(const char *s) {

int length = strlen(s);

while (s[length - 1] == ' ') length--;

if (length == 0) return 0;

for (int i = length - 1; i >= 0; i--)

if (s[i] == ' ') return length - i - 1;

return length;

}

};