1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-11 02:58:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (English)/单词频率(English) [words-frequency-lcci].html

29 lines
1.3 KiB
HTML
Raw Normal View History

<p>Design a method to find the frequency of occurrences of any given word in a book. What if we were running this algorithm multiple times?</p>
<p>You should implement following methods:</p>
<ul>
<li><code>WordsFrequency(book)</code> constructor, parameter is a array of strings, representing the book.</li>
<li><code>get(word)</code>&nbsp;get the frequency of <code>word</code> in the book.&nbsp;</li>
</ul>
<p><strong>Example: </strong></p>
<pre>
WordsFrequency wordsFrequency = new WordsFrequency({&quot;i&quot;, &quot;have&quot;, &quot;an&quot;, &quot;apple&quot;, &quot;he&quot;, &quot;have&quot;, &quot;a&quot;, &quot;pen&quot;});
wordsFrequency.get(&quot;you&quot;); //returns 0&quot;you&quot; is not in the book
wordsFrequency.get(&quot;have&quot;); //returns 2&quot;have&quot; occurs twice in the book
wordsFrequency.get(&quot;an&quot;); //returns 1
wordsFrequency.get(&quot;apple&quot;); //returns 1
wordsFrequency.get(&quot;pen&quot;); //returns 1
</pre>
<p><strong>Note: </strong></p>
<ul>
<li><code>There are only lowercase letters in book[i].</code></li>
<li><code>1 &lt;= book.length &lt;= 100000</code></li>
<li><code>1 &lt;= book[i].length &lt;= 10</code></li>
<li><code>get</code>&nbsp;function will not be called more than&nbsp;100000 times.</li>
</ul>