mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-11 02:58:13 +08:00
28 lines
1.1 KiB
HTML
28 lines
1.1 KiB
HTML
<p>设计一个方法,找出任意指定单词在一本书中的出现频率。</p>
|
||
|
||
<p>你的实现应该支持如下操作:</p>
|
||
|
||
<ul>
|
||
<li><code>WordsFrequency(book)</code>构造函数,参数为字符串数组构成的一本书</li>
|
||
<li><code>get(word)</code>查询指定单词在书中出现的频率</li>
|
||
</ul>
|
||
|
||
<p><strong>示例:</strong></p>
|
||
|
||
<pre>WordsFrequency wordsFrequency = new WordsFrequency({"i", "have", "an", "apple", "he", "have", "a", "pen"});
|
||
wordsFrequency.get("you"); //返回0,"you"没有出现过
|
||
wordsFrequency.get("have"); //返回2,"have"出现2次
|
||
wordsFrequency.get("an"); //返回1
|
||
wordsFrequency.get("apple"); //返回1
|
||
wordsFrequency.get("pen"); //返回1
|
||
</pre>
|
||
|
||
<p><strong>提示:</strong></p>
|
||
|
||
<ul>
|
||
<li><code>book[i]</code>中只包含小写字母</li>
|
||
<li><code>1 <= book.length <= 100000</code></li>
|
||
<li><code>1 <= book[i].length <= 10</code></li>
|
||
<li><code>get</code>函数的调用次数不会超过100000</li>
|
||
</ul>
|