class Solution { public: int lengthOfLastWord(string s) { int n = s.size(); int res = 0; int j = 0; for(j=n-1;j >= 0;j--){ if(s[j] != ' ') break; } for(int i=j;i >= 0;i--){ if(s[i] == ' ') break; res++; } return res; } };