Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions lcci/16.02.Words Frequency/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,22 @@ WordsFrequency.prototype.get = function (word) {
*/
```

```swift
class WordsFrequency {
private var cnt: [String: Int] = [:]

init(_ book: [String]) {
for word in book {
cnt[word, default: 0] += 1
}
}

func get(_ word: String) -> Int {
return cnt[word, default: 0]
}
}
```

<!-- tabs:end -->

<!-- end -->
16 changes: 16 additions & 0 deletions lcci/16.02.Words Frequency/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,22 @@ WordsFrequency.prototype.get = function (word) {
*/
```

```swift
class WordsFrequency {
private var cnt: [String: Int] = [:]

init(_ book: [String]) {
for word in book {
cnt[word, default: 0] += 1
}
}

func get(_ word: String) -> Int {
return cnt[word, default: 0]
}
}
```

<!-- tabs:end -->

<!-- end -->
13 changes: 13 additions & 0 deletions lcci/16.02.Words Frequency/Solution.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class WordsFrequency {
private var cnt: [String: Int] = [:]

init(_ book: [String]) {
for word in book {
cnt[word, default: 0] += 1
}
}

func get(_ word: String) -> Int {
return cnt[word, default: 0]
}
}