0058.cpp (246B)
1 class Solution { 2 public: 3 int lengthOfLastWord(string s) { 4 int i = s.size(), res = 0; 5 while (--i >= 0 && isspace(s[i])) 6 ; 7 while (i >= 0 && !isspace(s[i--])) 8 res++; 9 return res; 10 } 11 };