File tree Expand file tree Collapse file tree 3 files changed +45
-0
lines changed
lcci/16.02.Words Frequency Expand file tree Collapse file tree 3 files changed +45
-0
lines changed Original file line number Diff line number Diff line change @@ -203,6 +203,22 @@ WordsFrequency.prototype.get = function (word) {
203
203
*/
204
204
```
205
205
206
+ ``` swift
207
+ class WordsFrequency {
208
+ private var cnt: [String : Int ] = [: ]
209
+
210
+ init (_ book : [String ]) {
211
+ for word in book {
212
+ cnt[word, default : 0 ] += 1
213
+ }
214
+ }
215
+
216
+ func get (_ word : String ) -> Int {
217
+ return cnt[word, default : 0 ]
218
+ }
219
+ }
220
+ ```
221
+
206
222
<!-- tabs:end -->
207
223
208
224
<!-- end -->
Original file line number Diff line number Diff line change @@ -215,6 +215,22 @@ WordsFrequency.prototype.get = function (word) {
215
215
*/
216
216
```
217
217
218
+ ``` swift
219
+ class WordsFrequency {
220
+ private var cnt: [String : Int ] = [: ]
221
+
222
+ init (_ book : [String ]) {
223
+ for word in book {
224
+ cnt[word, default : 0 ] += 1
225
+ }
226
+ }
227
+
228
+ func get (_ word : String ) -> Int {
229
+ return cnt[word, default : 0 ]
230
+ }
231
+ }
232
+ ```
233
+
218
234
<!-- tabs:end -->
219
235
220
236
<!-- end -->
Original file line number Diff line number Diff line change
1
+ class WordsFrequency {
2
+ private var cnt : [ String : Int ] = [ : ]
3
+
4
+ init ( _ book: [ String ] ) {
5
+ for word in book {
6
+ cnt [ word, default: 0 ] += 1
7
+ }
8
+ }
9
+
10
+ func get( _ word: String ) -> Int {
11
+ return cnt [ word, default: 0 ]
12
+ }
13
+ }
You can’t perform that action at this time.
0 commit comments