题目链接:https://leetcode-cn.com/problems/length-of-last-word/
题目如下:
class Solution {
public:int lengthOfLastWord(string s) {int result=0;s.erase(s.find_last_not_of(' ')+1);for(int i=s.size()-1;i>=0;i--)if(s[i]!=' ') result++;else break;return result;}
};