@@ -47,13 +47,70 @@ wordsFrequency.get("pen"); //returns 1
47
47
### ** Python3**
48
48
49
49
``` python
50
+ class WordsFrequency :
50
51
52
+ def __init__ (self , book : List[str ]):
53
+ self .counter = collections.Counter(book)
54
+
55
+ def get (self , word : str ) -> int :
56
+ return self .counter[word]
57
+
58
+ # Your WordsFrequency object will be instantiated and called as such:
59
+ # obj = WordsFrequency(book)
60
+ # param_1 = obj.get(word)
51
61
```
52
62
53
63
### ** Java**
54
64
55
65
``` java
66
+ class WordsFrequency {
67
+
68
+ private Map<String , Integer > counter = new HashMap<> ();
69
+
70
+ public WordsFrequency (String [] book ) {
71
+ for (String word : book) {
72
+ counter. put(word, counter. getOrDefault(word, 0 ) + 1 );
73
+ }
74
+ }
75
+
76
+ public int get (String word ) {
77
+ return counter. containsKey(word) ? counter. get(word) : 0 ;
78
+ }
79
+ }
80
+
81
+ /**
82
+ * Your WordsFrequency object will be instantiated and called as such:
83
+ * WordsFrequency obj = new WordsFrequency(book);
84
+ * int param_1 = obj.get(word);
85
+ */
86
+ ```
56
87
88
+ ### ** JavaScript**
89
+
90
+ ``` js
91
+ /**
92
+ * @param {string[]} book
93
+ */
94
+ var WordsFrequency = function (book ) {
95
+ this .counter = {};
96
+ for (const word of book) {
97
+ this .counter [word] = (this .counter [word] || 0 ) + 1 ;
98
+ }
99
+ };
100
+
101
+ /**
102
+ * @param {string} word
103
+ * @return {number}
104
+ */
105
+ WordsFrequency .prototype .get = function (word ) {
106
+ return this .counter [word] || 0 ;
107
+ };
108
+
109
+ /**
110
+ * Your WordsFrequency object will be instantiated and called as such:
111
+ * var obj = new WordsFrequency(book)
112
+ * var param_1 = obj.get(word)
113
+ */
57
114
```
58
115
59
116
### ** ...**
0 commit comments