Ac 0ms:
class Solution {
public:
int lengthOfLastWord(string s) {
int len = s.length();
int i = len-1,count=0;
//aviod space end
while(s[i]==' ')i--;
while (i>=0&&s[i] != ' ')//it can be only one word
{
i--;
count++;
}
return count;
}
};
static const auto kSpeedUp = []() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
return nullptr;
}();