```
int lengthOfLastWord(string s) {
int a = s.find_last_of(' ');
if (a == -1) return s.length();
if (a == s.length() - 1){
while (a >= 0 && s[a] == ' ') a--;
if (a == 0) return 1;
if (a < 0) return 0;
return lengthOfLastWord(s.substr(0, a+1));
}
return s.length() - a - 1;
}
```