Skip to content

Commit 22e3fc6

Browse files
klever34thinkasany
andauthored
feat: add swift implementation to lcci problem: No.16.02 (#2726)
* Swift Implementation for LCCI 16.02 * Update lcci/16.02.Words Frequency/README_EN.md * Update lcci/16.02.Words Frequency/README.md --------- Co-authored-by: thinkasany <480968828@qq.com>
1 parent ace34c0 commit 22e3fc6

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

lcci/16.02.Words Frequency/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,22 @@ WordsFrequency.prototype.get = function (word) {
203203
*/
204204
```
205205

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+
206222
<!-- tabs:end -->
207223

208224
<!-- end -->

lcci/16.02.Words Frequency/README_EN.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,22 @@ WordsFrequency.prototype.get = function (word) {
215215
*/
216216
```
217217

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+
218234
<!-- tabs:end -->
219235

220236
<!-- end -->
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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+
}

0 commit comments

Comments
 (0)