mirror of
				https://gitee.com/coder-xiaomo/leetcode-problemset
				synced 2025-11-04 19:53:12 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			29 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			29 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
<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> get the frequency of <code>word</code> in the book. </li>
 | 
						||
</ul>
 | 
						||
 | 
						||
<p><strong>Example: </strong></p>
 | 
						||
 | 
						||
<pre>
 | 
						||
WordsFrequency wordsFrequency = new WordsFrequency({"i", "have", "an", "apple", "he", "have", "a", "pen"});
 | 
						||
wordsFrequency.get("you"); //returns 0,"you" is not in the book
 | 
						||
wordsFrequency.get("have"); //returns 2,"have" occurs twice in the book
 | 
						||
wordsFrequency.get("an"); //returns 1
 | 
						||
wordsFrequency.get("apple"); //returns 1
 | 
						||
wordsFrequency.get("pen"); //returns 1
 | 
						||
</pre>
 | 
						||
 | 
						||
<p><strong>Note: </strong></p>
 | 
						||
 | 
						||
<ul>
 | 
						||
	<li><code>There are only lowercase letters in 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> function will not be called more than 100000 times.</li>
 | 
						||
</ul>
 |