Skip to content

Commit a84c906

Browse files
authoredJan 27, 2025··
feat: add swift implementation to lcp problem: No.66 (#3998)
1 parent 452372e commit a84c906

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed
 

‎lcp/LCP 66. 最小展台数量/README.md

+23
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,29 @@ func minNumBooths(demand []string) (ans int) {
151151
}
152152
```
153153

154+
#### Swift
155+
156+
```swift
157+
class Solution {
158+
func minNumBooths(_ demand: [String]) -> Int {
159+
var maxBooths = [Int](repeating: 0, count: 26)
160+
161+
for day in demand {
162+
var dailyCount = [Int](repeating: 0, count: 26)
163+
for char in day {
164+
let index = Int(char.asciiValue! - Character("a").asciiValue!)
165+
dailyCount[index] += 1
166+
}
167+
for i in 0..<26 {
168+
maxBooths[i] = max(maxBooths[i], dailyCount[i])
169+
}
170+
}
171+
172+
return maxBooths.reduce(0, +)
173+
}
174+
}
175+
```
176+
154177
<!-- tabs:end -->
155178

156179
<!-- solution:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution {
2+
func minNumBooths(_ demand: [String]) -> Int {
3+
var maxBooths = [Int](repeating: 0, count: 26)
4+
5+
for day in demand {
6+
var dailyCount = [Int](repeating: 0, count: 26)
7+
for char in day {
8+
let index = Int(char.asciiValue! - Character("a").asciiValue!)
9+
dailyCount[index] += 1
10+
}
11+
for i in 0..<26 {
12+
maxBooths[i] = max(maxBooths[i], dailyCount[i])
13+
}
14+
}
15+
16+
return maxBooths.reduce(0, +)
17+
}
18+
}

0 commit comments

Comments
 (0)
Please sign in to comment.