58. 最后一个单词的长度 Posted on 2021-08-31 Edited on 2022-11-27 In leetcode Disqus: Symbols count in article: 224 Reading time ≈ 1 mins. 58. 最后一个单词的长度 123456789101112class Solution {public: int lengthOfLastWord(string s) { int end = s.size() - 1; int ret = 0; while(s[end] == ' ') --end; while(end >= 0 && s[end--] != ' ') ++ret; return ret; }};