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)/句子中的最多单词数 [maximum-number-of-words-found-in-sentences].html
2022-03-29 12:43:11 +08:00

39 lines
1.7 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>一个 <strong>句子</strong>&nbsp;由一些 <strong>单词</strong>&nbsp;以及它们之间的单个空格组成,句子的开头和结尾不会有多余空格。</p>
<p>给你一个字符串数组&nbsp;<code>sentences</code>&nbsp;,其中&nbsp;<code>sentences[i]</code>&nbsp;表示单个 <strong>句子</strong>&nbsp;</p>
<p>请你返回单个句子里 <strong>单词的最多数目</strong>&nbsp;</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre><b>输入:</b>sentences = ["alice and bob love leetcode", "i think so too", <em><strong>"this is great thanks very much"</strong></em>]
<b>输出:</b>6
<b>解释:</b>
- 第一个句子 "alice and bob love leetcode" 总共有 5 个单词。
- 第二个句子 "i think so too" 总共有 4 个单词。
- 第三个句子 "this is great thanks very much" 总共有 6 个单词。
所以,单个句子中有最多单词数的是第三个句子,总共有 6 个单词。
</pre>
<p><strong>示例 2</strong></p>
<pre><b>输入:</b>sentences = ["please wait", <em><strong>"continue to fight"</strong></em>, <em><strong>"continue to win"</strong></em>]
<b>输出:</b>3
<b>解释:</b>可能有多个句子有相同单词数。
这个例子中,第二个句子和第三个句子(加粗斜体)有相同数目的单词数。
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= sentences.length &lt;= 100</code></li>
<li><code>1 &lt;= sentences[i].length &lt;= 100</code></li>
<li><code>sentences[i]</code>&nbsp;只包含小写英文字母和&nbsp;<code>' '</code>&nbsp;</li>
<li><code>sentences[i]</code>&nbsp;的开头和结尾都没有空格。</li>
<li><code>sentences[i]</code>&nbsp;中所有单词由单个空格隔开。</li>
</ul>