>> >> >> Reference << << << <<<<<<Ref>>>>>>
>> >> >> Indexer << << << <<<<<<Idx>>>>>>
Matched: 0

Tags

    Categories

      Types

        Top Results

          LC58.LengthofLastWord
          M: 2026-04-27 - ljf12825

          题目

          字符串s由若干个单词和空格组成
          求最后一个单词的长度
          单词是指仅由字母组成、不包含任何空格字符的最大子字符串
          

          题解

          #include <iostream>
          #include <string>
          
          class Solution
          {
          public:
          	int lenthOfLastWord(std::string s)
          	{
          		int n = 0;
          		for (auto index = s.rbegin(); index != s.rend(); ++index)
          		{
          			if (*index != ' ') ++n;
          			else if (n > 0) break;
          		}
          		return n;
          	}
          };