Skip to content

Latest commit

 

History

History
70 lines (37 loc) · 1.57 KB

README_EN.md

File metadata and controls

70 lines (37 loc) · 1.57 KB

中文文档

Description

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?

You should implement following methods:

  • WordsFrequency(book) constructor, parameter is a array of strings, representing the book.
  • get(word) get the frequency of word in the book. 

Example:

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

Note:

    <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>
    

Solutions

Python3

Java

...