1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-10 18:48:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/最后一个单词的长度 [length-of-last-word].html
2022-03-29 12:43:11 +08:00

40 lines
1.2 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<p>给你一个字符串 <code>s</code>,由若干单词组成,单词前后用一些空格字符隔开。返回字符串中 <strong>最后一个</strong> 单词的长度。</p>
<p><strong>单词</strong> 是指仅由字母组成、不包含任何空格字符的最大子字符串。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>s = "Hello World"
<strong>输出:</strong>5
<strong>解释:</strong>最后一个单词是“World”长度为5。
</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>s = " fly me to the moon "
<strong>输出:</strong>4<strong>
解释:</strong>最后一个单词是“moon”长度为4。
</pre>
<p><strong>示例 3</strong></p>
<pre>
<strong>输入:</strong>s = "luffy is still joyboy"
<strong>输出:</strong>6
<strong>解释:</strong>最后一个单词是长度为6的“joyboy”。
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= s.length &lt;= 10<sup>4</sup></code></li>
<li><code>s</code> 仅有英文字母和空格 <code>' '</code> 组成</li>
<li><code>s</code> 中至少存在一个单词</li>
</ul>