class Solution {
public:
int lengthOfLastWord(string s) {
int ans=0,cur=s.length()-1;
while(s[cur]==' '){
cur--;
}
while(cur>=0&&s[cur]!=' '){
ans++;
cur--;
}
return ans;
}
};