Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit a84c906

Browse files
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‎

Lines changed: 23 additions & 0 deletions
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 -->
Lines changed: 18 additions & 0 deletions
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)

AltStyle によって変換されたページ (->オリジナル) /