class Solution {
public:
int lengthOfLastWord(string s) {
if ("" == s)
return 0;
while (*s.rbegin() == ' ')
s.erase(--(s.rbegin().base()));
auto const pos = s.find_last_of(' ');
if (pos == string::npos)
{
//not find space
return s.length();
}
else
{
string strTemp = s.substr(pos + 1);
return strTemp.length();
}
}
};