Leetcode 58. Length of Last Word | | Leetcode 58. Length of Last Word 文章作者:Tyan博客:noahsnail.com | CSDN | 简书 1. Description 2. Solution1234567891011121314class Solution {public: int lengthOfLastWord(string s) { int length = 0; int index = s.find_last_not_of(" "); if(index == -1) { return length; } while(index >= 0 && s[index--] != ' ') { length++; } return length; }}; Reference https://leetcode.com/problems/length-of-last-word/description/ 如果有收获,可以请我喝杯咖啡! 赏 微信打赏 支付宝打赏